q + lowercase letter to start recording macro, q again to stop
ctrl+v, select, shift + I for multiline editing.
Tag Archives: vim
Window stacking in VIM
Stolen shamelessly from this site.
map <c -J> </c><c -W>j</c><c -W>_ map </c><c -K> </c><c -W>k</c><c -W>_ set wmh=0 </c>
The first two lines allow you to switch between splits much more smoothly — just press
The last line allows splits to reduce their size to a single line (which includes the filename and position); this saves a lot of space when you have many splits open. By default, vim forces splits to include an additional line that contains the line of text the cursor was on in that file.
This gives you some sort of stacking functionality like in wmii
vim tips
replace foo with bar from line 10 to 20:
:10,20s/foo/bar/g
Using !cmd
to apply a command to a visual selection or a whole file. (e.g. “!sort -nr
“)
'gd'
(go to definition)
:earlier 5m
takes you back 5 minutes in the editing session (ignoring undos/redos)
in cmd mode ctrl-r ctrl-w pastes the word that’s currently under the
cursor in your active buffer. So if you want to replace aVeryLongWord
you’d do :%s/ctrl-r ctrl-w/ctrl-r ctrl-w edit a bit/g
.
^a and ^x to incr/decr a number in the text.
Sometimes after making many edits to an open file, you end up wondering what changes you made since it was last saved. In that case, use
:w !diff – %
qz ” record keystrokes into “z register;
” hit ‘q’ again to stop
@z ” play back macro in “z
10@z” play back macro in “z 10 times
@@ ” play back last macro
:registers z ” show macro/register contents
gt ” go to next tab
gT ” go to previous tab
line numbers in vim
type the following to turn on line numbers:
:set number
enter the following command to turn them off:
:set nonumber