How to split existing buffer vertically in vim?

26

16

I have list of buffers in vim. I can split buffer horizontally using :sb[N] where N is the buffer number. How can I split the buffer vertically ?

blacklife

Posted 2010-04-23T23:15:57.667

Reputation: 263

Answers

46

The vs and vsplit commands take a filename as an argument like :vs somefile to open a file in a vertical split.

To put an existing buffer in a split window you use the sb# command (where # is the buffer number). Splits in VIM default to horizontal, to change this, prefix your command with vert which forces a vertical split of the next split command.

:vert sb#

Where # is the buffer number

kyrisu

Posted 2010-04-23T23:15:57.667

Reputation: 1 405

I know :vsplit. I doesn't seem to take buffer number. – blacklife – 2010-04-23T23:53:05.470

1I thought it was to easy :P .. try :vert sbN -where N is the buffer number – kyrisu – 2010-04-24T00:12:06.407

wohoo! It works. – blacklife – 2010-04-24T00:41:08.153

@blacklife: so the answer is actually ":vert sbN" ? – akira – 2010-05-21T06:38:03.707

2Since :sb works with buffer names too, this will also works with buffer names: :vert sb vimrc – fphilipe – 2013-04-27T14:07:17.693

2

This is a command I created and added to my .vimrc to allow me to open a current buffer in a vertical split

command -nargs=1 Vsb call VsbFunction(<f-args>)

function VsbFunction (arg1)
  execute 'vert sb' a:arg1
endfunction

Brett Y

Posted 2010-04-23T23:15:57.667

Reputation: 306

you mean open all files currently in the buffer on vertical splits right? that was the answer i was looking for. – kroe – 2016-11-04T02:12:44.733

How am I supposed to execute this? – Santosh Kumar – 2019-08-31T01:32:41.673

:Vsb somefile – Brett Y – 2019-08-31T10:17:24.550

0

As kirysu said, but additionally with "positioning the other split".

:vert rightbelow sb otherfile.txt

or

:vert bel sb otherfile.txt

... opens a existing buffer, named otherfile.txt, in a split "right below" the existing one.
In the case of vertical splitting, it means "right side of the existing buffer".

Here you can use the [tab]-key too, to let vim complete the buffer-name!

(see :help :vert too, for further "positioning"-commands)

tron5

Posted 2010-04-23T23:15:57.667

Reputation: 101