How do I split the window vertically in Vim?
Answer
:vsplit
Explanation
The :vsplit command (or :vs for short) splits the current window vertically, creating a new window side-by-side with the current one. Both windows display the same buffer initially, but you can navigate to different files independently in each.
How it works
:vsplitcreates a vertical split showing the same file in both windows:vsplit filenameopensfilenamein the new split<C-w>vis the normal-mode shortcut for:vsplit
Example
You are editing main.go and want to reference utils.go side by side. Run:
:vsplit utils.go
Vim creates a new window to the left showing utils.go, while the original main.go remains visible on the right.
Navigating between splits
<C-w>h— move to the window on the left<C-w>l— move to the window on the right<C-w>j— move to the window below<C-w>k— move to the window above<C-w><C-w>— cycle to the next window
Tips
- Use
:split(or:sp) for a horizontal split instead - Use
<C-w>=to equalize the sizes of all open windows - Use
<C-w>>and<C-w><to resize a vertical split incrementally - Use
:vnewto open a vertical split with a new empty buffer - Use
:closeor<C-w>cto close the current split without quitting Vim - Use
:onlyor<C-w>oto close all splits except the current one - Use
<C-w>Tto break the current split out into a new tab - You can combine vertical and horizontal splits to create complex layouts