How to Create and Manage Multiple Split Windows in Vim
While Vim has a reputation as a simple editor for Linux, it has a lot of advanced features. One of them is the ability to work with multiple windows. Here’s how you can split and manage windows in Vim.
Sign up forfree
Forgot your password?
Create an account
*Required: 8 chars, 1 capital letter, 1 number
By continuing, you agree to thePrivacy PolicyandTerms of Use.You also agree to receive our newsletters, you can opt-out any time.

It’s easy to open a new window in Vim. If you’re already working in a file, you can split your existing window. This will allow you to view a different area of the file. You’d need to knowthe basics of how to use Vimto do so.
First, go to command mode by pressingEscape. Then type this command to split the window:

You can also split a window vertically by typing:
The result will resemble a GNU Screen or Tmux session, except that you’re able to’t detach it to keep it running.

To open multiple files when you start Vim, you can use the-ooption followed by the names of the files you want to edit:
The-O(uppercase O) option will split the screen vertically.

You can also start Vim with just the list of files and use the:allcommand to open windows for all of them. To open vertical windows, use this command:
Scrolling Windows in Vim
You’ll now have two different windows showing documents that you can scroll independently. To scroll the window forward, useCtrl + F, and to scroll the window backward, pressCtrl + B. You can also switch to showing the windows side-by-side withCtrl + v.
It’s possible to split windows indefinitely. You can also create a brand new window with a new file withCtrl + n.Ctrl + N, with a capital N, will create a new split window vertically.

You can also split a window with a new file with the:newcommand.
Switching Between Split Windows in Vim
Switching between Vim windows is also easy. Use theCtrl + Wprefix plus the direction of the window you want to move to. The movement keys are similar to the existingVim movement key commands.
For example, to move down, pressCtrl + W + j, and to move up, pressCtrl + W + k. To move to the window on the left, pressCtrl + W + h, and to move right, pressCtrl + W + l.
To go to the top window, useCtrl + W + t, and for the bottom window, typeCtrl + W + b.
You can swap the positions of the windows with theCtrl + KandCtrl + Jkeystrokes. These are capital letters, as Vim commands are case-sensitive. The former will move the current window to the top, and the latter will move it to the bottom.Ctrl + HandCtrl + Jwill do the same to vertically split windows.
Opening Terminal Windows in Vim
If you want to run shell commands or even an entire terminal session, you don’t have to leave Vim. You can run commands right within the editor.
To run a command, just type a colon (:), as you would with any other Vim command, an exclamation point (!), and the command. For example, to run an ls command in Vim:
This will show a new screen with the output from the command and prompt you to pressEnterto return to Vim.
you could also run a full terminal session with the:terminalcommand. This will split the window and start a terminal session within Vim. You can run multiple commands and run full-screen text programs like the man command. You can even run another Vim session if you want to.
Resizing Split Windows in Vim
It’s easy to change the size of your Vim windows. TheCtrl + W + PlusandCtrl + W + Minuskeys will increase and decrease the size of the current window by one line.
You can also specify the size of a window ahead of time by prefixing the:splitcommand with the number of lines you want the window to be. For example, to open a window three lines high, use this command:
Closing Split Windows in Vim
When you’ve finished working in a window, you’re able to close it with the:qcommand. If you have unsaved changes in a window and want to close it anyway, append an exclamation point:
To close every other window but the one you’re working on, use the:onlycommand. Again, you can append an exclamation point to close any unsaved windows.
To close every window and quit Vim entirely, use:qall. To do so without saving, use:qall!.
To save every window, use:wall.
You can also combine the save and quit operations:
Vim Lets You Edit Multiple Files at the Same Time
With Vim, you can easily edit multiple files and even run terminal commands by splitting windows and moving between them. Of the classic Unix text editors, this was a feature most associated with GNU Emacs.
While multiple windows have been part of Vim for a long time, you’re able to add features from other text editors to Vim as well.
Using the Vim text editor but wishing it was as functional as other text editors? Here’s how to install new features in Vim.
If an AI can roast you, it can also prep you for emergencies.
So much time invested, and for what?
Don’t let someone else take over your phone number.
Don’t let aging hardware force you into buying expensive upgrades.
Your phone’s camera app doesn’t show this, so it’s easy to miss.