Open a buffer as a vertical split in VIM

后端 未结 6 1064
醉酒成梦
醉酒成梦 2021-01-29 17:35

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?

<
相关标签:
6条回答
  • 2021-01-29 17:54

    The answer to the OP that I found most useful is embedded deep in Jerinaw's answer and a comment on it, and in Wolfson's answer. But I felt it might be brought out more. (Nor have those been voted most highly, even though they seemed to me the ones that answered OP best.)

    The answer to the question, Why is there not :vsbuffer, is that there is. It's called :vsplit and does the trick either as

    :vsplit NameOfBuffer

    OR

    :vsplit #NumberOfBuffer.

    (In this second use, take care to note that the hash # is significant. If you want to get to buffer number 3, you need to say :vsplit #3, not just :vsplit 3 which will instead create a new file named "3".)

    Again, this answer is embedded above, it's just not brought out clearly enough for the quick scanner, IMV.

    0 讨论(0)
  • 2021-01-29 17:59

    You can also combine :ls that lists your current buffers and the commands to open the desired buffer in either

    1. current window: :b <N/bufname>
    2. vertical split: :vsp | b <N/bufname>
    3. 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

    1. <leader>b
    2. <leader>v
    3. <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.

    0 讨论(0)
  • 2021-01-29 18:06

    you can use Neovim,like that:

    autocmd FileType python nmap <F5> :rightbelow vertical split <bar> :term python %<cr>
    
    0 讨论(0)
  • 2021-01-29 18:11

    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>
    
    0 讨论(0)
  • 2021-01-29 18:13

    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
    
    0 讨论(0)
  • 2021-01-29 18:13

    :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

    0 讨论(0)
提交回复
热议问题