New Location

My website has moved to http://www.jasonwhaley.com. Please visit there for the latest and only remain here for legacy content.

Tuesday, June 1, 2010

Periodically VIM - window resizing

[Periodically VIM is my regular VIM tips and discoveries section, inspired by what was Daily VIM]

The Tip: :res[ize] and :vertical res[ize] for resizing windows.

Usage: Split some windows using both :split and :vsplit. With your cursor in a particular window you can resize it using the following:
  • :res N - Changes the height of a window to be N rows.
  • :res +N - Adds N rows to the height of a window
  • :res -N - Removes N rows from the height of a window
  • :vertical res N - Changes the width of a window to be N characters
  • :vertical res +N - Adds N characters to the width of a window
  • :vertical res -N - Removes N characters from the width of a window
  • ctrl-w = - Makes all windows visible in VIM approximately the same height.

What Is It Good For?: Very rarely am I in VIM without having multiple windows open to look at multiple files at the same time (or perhaps to look at the same file in two different locations). These commands are ultra useful to size the windows to an appropriate width and height for the given task.

1 comment:

Scott S McCoy said...

You forgot CTRL_W-_ which maximizes the current buffer. I use this several dozen times a day.

Also useful, CTRL_W-H, CTRL_W-J, CTRL_W-K, CTRL_W-L which push a buffer in a given direction.

I often use two vertical panes of several horizontal buffers. To move my buffers from one stack to the next, I use the following macros in my ~/.vimrc:

map :call MoveBuf("h")
map :call MoveBuf("l")
map :call MoveBuf("j")
map :call MoveBuf("k")

function! MoveBuf(direction)
let bufno = bufnr("%")
hide
exec "wincmd " . a:direction
new
exec "buffer " . bufno
endfunction


If you have 4 buffers, in a 2 x 2 square, you can use this macro (CTRL_W-META_H, J, K and L respectively) to move the current buffer in to the next group, left, down, up and right, respectively.