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

How do I split the Vim window to view two files at once?

Answer

:split

Explanation

The :split command (or <C-w>s) splits the current window horizontally, creating a new window above with the same file. Use :split filename to open a different file in the new split.

How it works

  • :split or <C-w>s creates a horizontal split (one window above, one below)
  • :vsplit or <C-w>v creates a vertical split (side by side)
  • :split filename opens a specific file in the new split

Navigating between splits

  • <C-w>w cycles between windows
  • <C-w>h/j/k/l moves to the left/below/above/right window
  • <C-w>o closes all windows except the current one

Example

:split header.h     " open header.h in a horizontal split
:vsplit main.c      " open main.c in a vertical split

Tips

  • Resize horizontally with <C-w>+ and <C-w>-
  • Resize vertically with <C-w>> and <C-w><
  • <C-w>= makes all splits equal size
  • :only closes all splits except the current one

Next

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