Open a buffer as a vertical split in VIM

后端 未结 6 1190
醉酒成梦
醉酒成梦 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: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
    2. vertical split: :vsp | b
    3. horizontal split: :sp | b

    For this, I've added the following mappings to my ~/.vimrc (order of mappings represents the above list of desired windows)

     nnoremap b :ls:b
     nnoremap v :ls:vsp\|b
     nnoremap s :ls:sp\|b
    

    Based on this, you can see the buffer list as soon as you hit

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

提交回复
热议问题