Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swap two windows when there are three

Tags:

vim

I have the following window arrangement in Vim:

┌─────┬─────┐
│     │  2  │
│  1  ├─────┤
│     │  3  │
└─────┴─────┘

I want to swap windows 2 and 3. Now window 2 is active. CTRL-wJ wouldn't work, because it will then bring window 2 to the bottom and window 1 and 3 on the top as two vertically split windows.

After that, I tried to use other CTRL-wH/J/K/L movements, but wasn't able to achieve the final result.

How can one actually do that?

like image 676
Qiang Li Avatar asked Jul 18 '19 08:07

Qiang Li


2 Answers

:h window-moving (or simply :h windows and then browsing down) lists all such stuff.

I believe you want CTRL-wCTRL-x (or CTRL-wx) (Window eXchange).

like image 82
Matt Avatar answered Sep 24 '22 01:09

Matt


I do not believe that Matt's answer is what you are looking for. It only allows to swap the window with the next window. This may work for the given example but not for more complex situations.

I use the vim-windowswap plugin which allows to swap any two windows: https://github.com/wesQ3/vim-windowswap

like image 37
Doktor OSwaldo Avatar answered Sep 22 '22 01:09

Doktor OSwaldo