Learn Vim at your own pace with my self-study Core Vim Course.

Learn more

Learn Vim at your own pace with my self-study Core Vim Course.

Working with windows

#7

Run time:

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.

Shownotes

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
Comments

Level-up your Vim

Training

Boost your productivity with a Vim training class. Join a public class, or book a private session for your team.

Drew hosted a private Vim session for the shopify team that was one of the best workshops I have ever attended.

John Duff, Director of Engineering at Shopify

Publications

Make yourself a faster and more efficient developer with the help of these publications, including Practical Vim (Pragmatic Bookshelf 2012), which has over 50 five-star reviews on Amazon.

After reading it, I've switched to vim as my default editor on a daily basis with no regrets. ★★★★★

Javier Collado

Learn to use Vim efficiently in your Ruby projects

In association with thoughtbot, one of the most well respected Rails consultancies in the world, I've produced a series of screencasts on how to make navigating your Ruby projects with Vim ultra-efficient. Along the way, you’ll also learn how to make Ruby blocks a first-class text object in Vim. This lets you edit Ruby code at a higher level of abstraction. Available to buy from thoughtbot..