Last Updated: February 25, 2016
·
619
· fifthposition

Turn Vim Into Vim, But With Windows

Used with caution and in conjunction with the correct amounts of coffee, Vim windows can be powerful allies in any war against the not getting done of things. You can split a window in Vim using (but of course!) :split (abbreviated :sp). This splits the current window horizontally. :vsplit (abbreviated :vs) will split it vertically. Using either, you can specify a file to open in the current window while you are at it. :sp filename.txt, for example, will open filename.txt and split the current window horizontally.

Having split up your one window into windows, you can use Ctrl+w w to move to the next open window; it will cycle through each window you have open. Far better, however, are the standard Vim movement commands. Ctrl+w j will move you to the next window down; Ctrl+w l will move you to the window to the right; and so on. You can also use the arrow keys to do this, but you are using Vim, so instead you say: “Arrow keys? What arrow keys?”

Windows, split horizontally or vertically, can be resized. Ctrl+w + increases a window’s height; Ctrl+w - shortens it; Ctrl+w < narrows it; Ctrl+w > makes it wider. As elsewhere in Vim, you can precede any of these commands with the number of times to run it. For example, you might use 4 Ctrl+w < to run the “narrow window” command four times. (In fact, this particular bit also applies to the movement commands of the preceding paragraph: 2 Ctrl+w j moves you two windows down.)

And finally: :q, when more than one window is open, will only close the current window. To close all of the open windows and exit Vim entirely, use :qa. To save all of your open files and close all of the windows, use :wqa. If at all possible, check for the presence of rats with little bags of jelly beans in neighboring trees before you open the windows again.