Put a ‘c’ after a substitute command #
Not always needed but does help keeping control of your changes. If in stead of this:
s/foo/bar/gYou write this:
s/foo/bar/gcThen vim will ask for confirmation on every change. This can help prevent you mutilating a document entirely.
vim-airline #
If like me you mostly use vim through a terminal that by default does not use the xterm-256color terminal type using the vim-airline plugins may not be what you want.
My solution:
Non greedy match #
If you need the shortest match between quotes or whatever adding .\\{-} to the pattern turns the match from greedy to non greedy.
Take the following line:
item1="1" item="2"
A normal substitute like this:
s/\".*\"/foo/Will result in:
item1=foo
Changing the substitute with .\{-}:
s/\".\{-}\"/foo/Will result in:
item1=foo item="2"
See: nongreedy for more information.
Move matching lines to bottom #
v[command]: inverse matchnormal[action]: Execute Normal mode commandsdd[command]: delete (cut) commandG[command]: go to the end of the filep[command]: paste line in buffer
Match a pattern and uppercase the match #
s[command]: substitute\(<pattern>\)[pattern]: store the patterns results for use in the replacement..\{-}[pattern]: non greedy match\>[pattern]: end of a word\U[action]: uppercase\1: result of the first\(<pattern>\)\E: end of\u,\U,\land\L.
See: substitute