问题
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.
EDIT: 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:
Function:
" Vertical Split Buffer Function
function VerticalSplitBuffer(buffer)
execute "vert belowright sb" a:buffer
endfunction
Mapping:
" 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
回答1:
Try:
:vert sb N
which will open a left vertical split (by default, unless you have modified some options).
To open a split to the right, on the other hand:
:vert belowright sb N
回答2:
:vsp | b1
1 being some buffer number. Use buffers to list all buffers.
Here's some additional info on splits, if you're interested. Link
回答3:
You can ease your pain by adding the following to your .vimrc
cabbrev vb vert sb
Now you can use it in the following way.
:vb <buffer>
回答4:
you can use Neovim,like that:
autocmd FileType python nmap <F5> :rightbelow vertical split <bar> :term python %<cr>
回答5:
You can also combine :ls that lists your current buffers and the commands to open the desired buffer in either
- current window:
:b <N/bufname> - vertical split:
:vsp | b <N/bufname> - horizontal split:
:sp | b <N/bufname>
For this, I've added the following mappings to my ~/.vimrc (order of mappings represents the above list of desired windows)
nnoremap <leader>b :ls<cr>:b<space>
nnoremap <leader>v :ls<cr>:vsp<space>\|<space>b<space>
nnoremap <leader>s :ls<cr>:sp<space>\|<space>b<space>
Based on this, you can see the buffer list as soon as you hit
<leader>b<leader>v<leader>s
and then just enter the desired buffer number N. This will then open the buffer in the desired window. You can of course still use a part of the buffer name bufname as well.
I mapped the <leader> to , based on
let mapleader = ","
For some people (e.g. me) this could even replace plugins like MiniBufExpl and thus save space on the screen.
来源:https://stackoverflow.com/questions/4571494/open-a-buffer-as-a-vertical-split-in-vim