Open a buffer as a vertical split in VIM

If you are editing a file in VIM and then you need to open an existing buffer (e.g. from your buffer list: :buffers) how can you open it in a vertical split?

I know that you already can open it with a normal split like:

:sbuffer N

Wehere N is the buffer number you want, however, the above opens that N buffer horizontally, not vertically.

I’m also aware that you can change the window placement after opening and have a Vertical Split like so:

Ctrl-W H
Ctrl-W L

Which will vertically split the window to the right or the left.

It seems to me that if there is a sbuffer there should be a vsbuffer but that doesn’t exist (not that I am aware of)

Also, please note that I am not looking for a plugin to solve this question. I know about a wealth of plugins that will allow you to do this.

I am sure I might be missing something that is already there.

In the best spirit of collaboration, I have created a simple Function with a Mapping if someone else stumbles across this issue and do not want to install a plugin:


" Vertical Split Buffer Function
function VerticalSplitBuffer(buffer)
    execute "vert belowright sb" a:buffer 


" Vertical Split Buffer Mapping
command -nargs=1 Vbuffer call VerticalSplitBuffer(<f-args>)

This accomplishes the task of opening a buffer in a right split, so for buffer 1, you would call it like:

:Vbuffer 1

6 Answers

Leave a Comment