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

The first two lines allow you to switch between splits much more smoothly — just press to open and maximize the split below the current one and to open and maximize the split above the current one. I chose these mappings because they correspond to vi’s default up and down keys, you might want to use different key combinations if you’ve ever used an editor that had hotkeys for moving from one open file to another.

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:


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

Vim cheatsheet