This is an old revision of the document!
Search and Replace
Typical Syntax
- :%s/SEARCH/REPLACEMENT/g
- % - tells vim to search the entire file
- g - tells vim to replace all instances on each line, instead of just the first
clear search highlighting
- :let @/=''
Newline Replace
- using \n as a replacement will NOT break the lines as expected (\n can be used as the search pattern)
- instead, type :%s/SEARCH/
- at this point, press CTRL-V, Enter (you should now see :%s/SEARCH/^M
- finish your pattern: :%s/SEARCH/^M/g (all SEARCH occurrences will be replaced with newlines, and lines WILL break)
- tab can also be accomplished the same way, but \t works anyway
- when using gvim (Windows), CTRL-V is probably mapped to paste from the clipboard; instead, use CTRL-Q the same way