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

How do I switch between split windows in Vim?

Answer

<C-w><C-w>

Explanation

The <C-w><C-w> (Ctrl+w Ctrl+w) command cycles the cursor to the next window in the current tab. If you have multiple splits open, this is the quickest way to jump between them without reaching for the mouse.

How it works

  • <C-w> is the window command prefix — it tells Vim the next keystroke is a window operation
  • The second <C-w> (or just w) moves the cursor to the next window in a clockwise order
  • When you reach the last window, it wraps around to the first

Example

You have two files open side by side with :vsplit:

┌──────────┬──────────┐
│  file1   │  file2   │
│  (active)│          │
└──────────┴──────────┘

Pressing <C-w><C-w> moves the cursor to file2. Pressing it again moves back to file1.

Directional window navigation

For more precise control, use directional keys after <C-w>:

  • <C-w>h — move to the window on the left
  • <C-w>j — move to the window below
  • <C-w>k — move to the window above
  • <C-w>l — move to the window on the right

Tips

  • Use <C-w>p to jump to the previously active window (toggle between two windows)
  • Use <C-w>t to jump to the top-left window
  • Use <C-w>b to jump to the bottom-right window
  • Many users map <C-h>, <C-j>, <C-k>, <C-l> to window navigation for faster switching:
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
  • Use :only or <C-w>o to close all windows except the current one

Next

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