Switching and resizing windows in vim

Ovid on 2009-10-27T10:52:14

I've gotten really tired of manually switching and resizing windows in vim. You can create more than one window in vim with :split or :vpslit, but navigating between them is often an annoying combination of "control w, direction key towards the window you want go to". Of course, if you hit the wrong direction key, you don't move anywhere and you silently curse because you were hitting "h" instead of "j". But then the windows often take up large chunks of real estate, so they're tough to read, but you don't want to keep only one window open and switching buffers all the time, so basically, window navigation can be a pain (even with BufExplorer and other plugins).

What some vim users aren't aware of is that you can type "control W, control W" and it will simply cycle you to the next window. You have to do this a few times if you have more than one window open, but since you don't have to move your fingers and remember navigation keys, it's quick and easy. Thus, I wrote this mapping (this does something similar to what other developers on our team do, but fits my work style a touch better):

noremap w :res

In other words, it automatically switches to the next window and resizes it. You can still see the other windows, but they're out of the way.


Ctrl+W _

Smylers on 2009-10-27T12:57:23

The :res command also has a keystroke, Ctrl+W _.

winheight/winwidth

ziggy on 2009-10-27T14:48:46

There's also :set winheight and :set winwidth

Each of these set the default height/width of the current window, so whatever you switch to takes up the appropriate amount of room.

Vim tips

runrig on 2009-10-27T14:54:50

I use this mapping from VIM Tips:

map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_