This article provides some tips on how to use multiple windows in
Vim.
Start Vim with n multiple windows
- n verticals windows.
vim -On filenames
- n horizontal windows.
vim -on filenames
Note: n is the number of windows.
Close a window
- Close the current window.
Ctrl+W c
- Close the current window. If it is the only window left, quit Vim.
Ctrl+W q
Split a window
- Split horizontally the current file.
Ctrl+W s
- Split horizontally and open a file.
:sp filename
- Split vertically the current file.
Ctrl+W v
- Split vertically and open a file.
:vsp filename
Move the cursor between windows
- Move to the right window from the current windows.
Ctrl+W l
- Move to the left window from the current windows.
Ctrl+W h
- Move to the top window from the current windows.
Ctrl+W k
- Move to the bottom window from the current windows.
Ctrl+W j
- Move to the next window below the current one. If no below window exist, move to the top window.
Ctrl+W w
Rotate windows location
- Move the current window to the right.
Ctrl+W L
- Move the current window to the left.
Ctrl+W H
- Move the current window to the top.
Ctrl+W K
- Move the current window to the bottom.
Ctrl+W J
Window resizing
Resizing windows can be made by using the mouse as well as the following commands.
- Make all windows equal in height.
Ctrl+W =
- Increase height.
Ctrl+W +
- Decrease height.
Ctrl+W -
Note: Thanks to Ferd T-H, resizing could also be done by using
Ctrl+W < or >
Conclusion
I hope that these commands are enough for you to start using windows in Vim. However, if you know some good command(s) to please don’t hesitate to leave a comment.