vimtricks.wiki Concise Vim tricks, one at a time.

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

  • :vsplit creates a vertical split showing the same file in both windows
  • :vsplit filename opens filename in the new split
  • <C-w>v is 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 :vnew to open a vertical split with a new empty buffer
  • Use :close or <C-w>c to close the current split without quitting Vim
  • Use :only or <C-w>o to close all splits except the current one
  • Use <C-w>T to break the current split out into a new tab
  • You can combine vertical and horizontal splits to create complex layouts

Next

How do I edit multiple lines at once using multiple cursors in Vim?