Wednesday, June 13, 2007

useful vim commands

Timetravel



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:

:undolist


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:

%s/argv\[\d\]/plotprefix/g


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

.,+4s/something/somethingelse/g


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

%s/\<\a*.cpp\>/..\/&/g


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

%norm jdd



See: http://www.geocities.com/volontir for a load of useful vim regular expression stuff.

1 comment:

nobodycares said...

Also worth checking out the latex extension pack