I know it's possible to open a new file in a split, with :split
or :vsplit
, but is it possible to open a new split with an existing buffer, potentially leveraging autocomplete?
2 Answers
The sbuffer
command will let you create a split with an existing buffer name or number. :sb#
will open a split with buffer number #
(as displayed in the :buffers
list). :sb foo
will open a split with the buffer named foo
. Tab-complete will cycle the available buffer names.
You can use :vertical sb...
if you want a vertical split instead of the default, horizontal, one.
-
2Is there a less verbose way to open an existing buffer in a new vertical split? Something like
:v sb
maybe?– zepp133Apr 28, 2018 at 13:52 -
2I believe “vertical” can only be shortened to “vert” so if you want something more concise you’ll have to make a custom command/function/etc– user72Apr 28, 2018 at 14:14
-
2I use this mapping to do the job.
ls
lists all opened buffers, so you don't have to remember the name :)nnoremap <leader>vb :ls<cr>:vertical sb<space>
– Mattia72Feb 3, 2020 at 7:33
:(v)split <name_of_buffer>
or :(v)split #<buffer_number>
This answer shows a shorter way to @user72's answer above and @zepp.lee's comment.
For example, you can open buffer 2 in a vertical split with
:vsp #2
or
:vsp test.js
-
1Welcome to this site @alexhg! We encourage our users to create detailed answers to make sure they are as useful as possible to other readers: here it would be useful if you explained why you suggest using this solution, you could also link to the doc. For now your answer has been flagged as being "low quality" but you can use the "edit" button to fix that.– statoxSep 2, 2019 at 18:29
-
3The
:(v)sp #<buffer_number>
does work correctly but typically I don't know the buffer number I want. Using the name of the buffer is again something I don't typically know as it requires the full path of the buffer. The question was also hoping for auto-completion, the:vert sb <buffer_stub>
followed by<tab>
will auto-complete the buffer for you, that doesn't work for:vsp
unfortunately.– icc97Sep 21, 2020 at 3:30 -
Autocompletion with
<tab>
does work for me if I type the name of a buffer (without having to type the full path). I ignore if it's due to my additional settings.– alexhgSep 22, 2020 at 7:15
:sp
(lit
) or:vs
(plit
) with no argument? :)