Subscribe for free with iTunes, Twitter, or RSS (Ogg or Quicktime).

Vimcasts

Working with windows

#7

In Vim, you can view several buffers at once by loading them into multiple windows. This episode demonstrates all the essentials of working with windows: opening, closing, resizing, moving between and rearranging them.

Download

OGG 7.2 MB

Quicktime 8.2 MB

Opening split windows

command action
ctrl-w s split the current window horizontally, loading the same file in the new window
ctrl-w v split the current window vertically, loading the same file in the new window
:sp[lit] filename split the current window horizontally, loading filename in the new window
:vsp[lit] filename split the current window vertically, loading filename in the new window

Closing split windows

command action
:q[uit] close the currently active window
:on[ly] close all windows except the currently active window

Changing focus between windows

command action
ctrl-w w cycle between the open windows
ctrl-w h focus the window to the left
ctrl-w j focus the window to the down
ctrl-w k focus the window to the up
ctrl-w l focus the window to the right

I have the following lines in my .vimrc file:

map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

Resizing windows

You can resize windows by clicking on the boundary between windows, and dragging it to your prefered size. The following key commands also help:

command action
ctrl-w + increase height of current window by 1 line
ctrl-w - decrease height of current window by 1 line
ctrl-w _ maximise height of current window
ctrl-w | maximise width of current window

Moving windows

command action
ctrl-w r rotate all windows
ctrl-w x exchange current window with its neighbour
ctrl-w H move current window to far left
ctrl-w J move current window to bottom
ctrl-w K move current window to top
ctrl-w L move current window to far right