Vim: Delete buffer without losing the split window

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-29 02:19:28

问题


When a buffer gets deleted (the "bd[elete]" command), it not only deletes the buffer but also removes the split window that buffer was in.

Is there a way to delete/unload a buffer and keep the window split?


回答1:


I really like bufkill.vim there is a github repo as well




回答2:


bp|bd # will do it.


Details:bp("buffer previous") moves us to a different buffer in the current window (bn would work, too), then bd # ("buffer delete" "alternate file") deletes the buffer we just moved away from. See: help bp, help bd, help alternate-file.




回答3:


You can add the following to your .vimrc to have Bd work as bd but without touching the window splits:

command Bd bp\|bd \#

I found this as a useful complement to what Mud answered.




回答4:


See deleting a buffer without closing the window on VIM tips wiki.




回答5:


I do something similar to @Mud, but switch to previous view buffer, #, instead of the previous buffer in buffer list. Here is a binding key in my .vimrc:

nnoremap <silent> <leader>q :lclose<bar>b#<bar>bd #<CR>

Close Location windows, if exist, switch to the previous view buffer, and then close the last switched buffer.




回答6:


My Choice is

:sb # | bd #
:sb 1 | bd #
: <1. Recall Buffer> | <2. Delete Buffer>

Think Like that! /// <1. Recall Buffer> | <2. Delete Buffer>

:vert sb 2 | bd #
:vert sb <tab key~completed file(buffer)name> | bd #

why?! It's easy to remember 3 (+ 1) keyword!

  1. sb split_buffer
  2. bd delete buffer ▶ simple 2 keywords
  3. # or Number of buffer
  4. vert ▶ short_form of vertical (split_buffer or else)

That are easy and very useful in many other many case!

Have a nice Day! :)




回答7:


I used to use :

:bp<bar>sp<bar>bn<bar>bd<CR>

But I found certain occasions where it closed my window. On top of that the next or previous buffer might not be what you want to be displayed in the split.

Now I do this :

  • switch to the buffer I want to work on
  • Delete the alternate buffer

nnoremap <leader>d :bd#<CR>



来源:https://stackoverflow.com/questions/4465095/vim-delete-buffer-without-losing-the-split-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!