Wednesday, June 13, 2007

useful vim commands


Vim 7 lets you move forward and backward a duration in time. For example:

:earlier 1h
:later 5m
:earlier 10s

What's also neat is that vim stores undo branches. So say you undo something, make some edits, then decide that you didn't really want to undo you can still go back to the previous state. Simply type:


to view the various buffers and:

:undo <number>

to go to the buffer

Spell checking

To enable spell checking type:

:set spell

All your spelling errors will be highlighted. From command mode use:

]s - next spelling error
[s - previous spelling error
z= - correct spelling from close matches

Record a macro

press q followed by one of 0 to 9 or a to z in command mode. do stuff... press q in command mode. Then press @ followed by 0-9 a-z (as you entered before) to play the macro. Press @@ to repeat the last macro.

Simple search and replace with a number in it

Search for all argv[NUMBER] and replace with plotprefix. Where NUMBER is um a number:


Replace something with somethingelse over the next 4 lines from the current cursor position:


Replace whatever.cpp with ../whatever.cpp where whatever is any character string:


Delete every other line, no idea how it works, in command mode:

%norm jdd

See: for a load of useful vim regular expression stuff.

1 comment:

nobodycares said...

Also worth checking out the latex extension pack