Tuesday 20 July 2010

Vim search replace

Search Replace

Over certain lines:

Command to find 'search' and put 'replace' there instead. On lines 8 -> 10. g = all of them
  • :8,10 s/search/replace/g 

Confirm each replace:

Note the 'c'
  • :%s/search/replace/gc

Format a json file: (requires jq to be installed):

  •  :%!jq . %
You may also need:
  •  :set filetype=json

Save parts of a file:

  • Select with 'v'
  • `:w filename`
To load a file into current buffer:
  • `:r filename` 

Tabs:

  • switch tabs: CTRL-W 
  • open filename in new tab: :split filename

Other

  • R = like r but replace many chars


No comments:

Post a Comment