How can I swap positions of two open files (in splits) in vim?
Asked 07 September, 2021
Viewed 2.9K times
  • 50
Votes

Assume I've got some arbitrary layout of splits in vim.

____________________
| one       | two  |
|           |      |
|           |______|
|           | three|
|           |      |
|___________|______|

Is there a way to swap one and two and maintain the same layout? It's simple in this example, but I'm looking for a solution that will help for more complex layouts.

UPDATE:

I guess I should be more clear. My previous example was a simplification of the actual use-case. With an actual instance: alt text

How could I swap any two of those splits, maintaining the same layout?

Update! 3+ years later...

I put sgriffin's solution in a Vim plugin you can install with ease! Install it with your favorite plugin manager and give it a try: WindowSwap.vim

a little demo

12 Answer