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

How do I rearrange window splits by moving a window to a different side of the screen?

Answer

<C-w>H / <C-w>J / <C-w>K / <C-w>L

Explanation

The <C-w>H, <C-w>J, <C-w>K, and <C-w>L commands move the current window to the far left, bottom, top, or right of the screen respectively, rearranging your entire split layout. Unlike <C-w>h/j/k/l (lowercase) which navigate between windows, the uppercase versions relocate the window itself.

How it works

  • <C-w>H moves the current window to the far left, making it a full-height vertical split
  • <C-w>L moves it to the far right, full-height vertical split
  • <C-w>K moves it to the top, making it a full-width horizontal split
  • <C-w>J moves it to the bottom, full-width horizontal split
  • The moved window takes up the full height or width of the screen on its new side

Example

Suppose you have two horizontal splits (one above the other):

┌─────────────┐
│   file_a    │
├─────────────┤
│   file_b    │
└─────────────┘

With the cursor in file_b, press <C-w>L to move it to the right side, converting the layout to vertical splits:

┌──────┬──────┐
│      │      │
│file_a│file_b│
│      │      │
└──────┴──────┘

Or from that layout, with the cursor in file_a, press <C-w>J to move it to the bottom:

┌─────────────┐
│   file_b    │
├─────────────┤
│   file_a    │
└─────────────┘

Tips

  • This is the fastest way to convert between horizontal and vertical split layouts without closing and reopening windows
  • Use <C-w>r to rotate windows within the current row or column without changing the layout structure
  • Use <C-w>R to rotate in the reverse direction
  • Use <C-w>x to exchange the current window with the next one in the same row or column
  • <C-w>T moves the current window to a new tab page — useful when you want to give a file its own full-screen workspace
  • Combine with <C-w>= afterward to equalize window sizes after rearranging
  • These commands work with any number of splits — the moved window always occupies the full extent of the chosen edge, and other windows rearrange to fill the remaining space

Next

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