docs:vim:search_and_replace

This is an old revision of the document!


  • :%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
  • :let @/=''
  • 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
  • docs/vim/search_and_replace.1206560520.txt.gz
  • Last modified: 2008/08/03 00:25
  • (external edit)