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

How do I swap the position of two windows?

Answer

<C-w>r

Explanation

The <C-w>r command rotates windows in the current row or column. This effectively swaps the positions of windows.

How it works

  • <C-w>r rotates windows downward/rightward
  • <C-w>R rotates in the opposite direction
  • <C-w>x exchanges the current window with the next one

Example

With two horizontal splits (file A on top, file B below), <C-w>r moves file B to the top and file A to the bottom.

Tips

  • <C-w>x exchanges with the next window (more targeted)
  • <C-w>H/J/K/L moves the current window to the far left/bottom/top/right
  • These uppercase versions change the layout structure
  • <C-w>H converts a horizontal split to vertical

Next

How do you yank a single word into a named register?