How do I rotate or swap window positions in Vim?
Answer
<C-w>R
Explanation
Vim provides commands to rotate windows within a row or column, and to swap the current window with another. <C-w>R rotates all windows upward/leftward, while <C-w>r rotates downward/rightward, enabling quick layout rearrangement.
How it works
<C-w>r— rotate windows downward/rightward<C-w>R— rotate windows upward/leftward<C-w>x— exchange current window with the next one- These operate on windows in the same row or column
Example
Before <C-w>R:
+-------+-------+
| Win A | Win B |
+-------+-------+
| Win C | Win D |
+-------+-------+
After <C-w>R (on top row):
+-------+-------+
| Win B | Win A |
+-------+-------+
| Win C | Win D |
+-------+-------+
Tips
<C-w>xswaps only two adjacent windows — simpler for targeted swaps- Use
<C-w>H/J/K/L(uppercase) to move a window to the far edge - Rotation wraps around — the last window becomes the first
- Combine with
<C-w>=after rearranging to equalize sizes