0

Let's say we have 3 buffers (A, B, C) open in Vim arranged as follows

-----------------------------------------
|                  |                    | 
|                  |                    | 
|                  |                    | 
|        A         |                    | 
|                  |                    | 
|                  |                    | 
|------------------|          B         | 
|                  |                    |     
|                  |                    | 
|         C        |                    | 
|                  |                    | 
|                  |                    | 
-----------------------------------------

and we want to rearrange it as

-----------------------------------------
|                  |                    | 
|                  |                    | 
|                  |                    | 
|                  |         B          | 
|                  |                    | 
|                  |                    | 
|         A        |--------------------| 
|                  |                    |     
|                  |                    | 
|                  |         C          | 
|                  |                    | 
|                  |                    | 
-----------------------------------------

I know I can do this by closing C and reopening it after splitting B. Is there a simple way to do this where I don't have to close buffers and I can rearrange the windows directly?

6
  • You'll probably get a better answer, faster, at vim.stackexchange.com
    – chepner
    Commented Jan 13, 2022 at 18:26
  • Thanks for the tip Commented Jan 13, 2022 at 18:32
  • 1
    It's unclear what the pattern is here. Assume there is a shortcut for doing what you want. Would the shortcut move c from the left to right? If you press it again, does it move C back to the left side? Does it move B to the top half of A? If you can clearly define what behavior you'd want out of this shortcut, that would help greatly.
    – wxz
    Commented Jan 13, 2022 at 19:04
  • If you're asking what I want, it would be something like how the i3 Windows Manager manages things. So in your specific example, if I press the same shortcut when it's in the second state it would then split the screen into three vertical windows. Based on the answer given, though, it doesn't look like Vim has this functionality built in. Commented Jan 13, 2022 at 20:53
  • 1
    If you can pin down the algorithm, you can customize your own shortcut for doing this.
    – wxz
    Commented Jan 14, 2022 at 4:47

1 Answer 1

1

You wouldn't "close" the buffer C, only the window that displays it.

Vim has dedicated normal mode commands for:

  • switching a window and the next one in a row or column,
  • rotating the whole window layout,
  • pushing a window to the far top, far right, far bottom, and far left,

but it doesn't have one for moving a window to an arbitrary point so, assuming the window you want to move has the focus, the command should look like this:

:q|winc w|sp c

which is not too shabby. You might be able to find a plugin that provides the level of control you are after on https://www.vim.org.

1
  • Thanks for the answer. Commented Jan 13, 2022 at 20:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.