colorsiop.blogg.se

Vim close all windows but current one
Vim close all windows but current one




vim close all windows but current one

  • bufkill unload/delete/wipe a buffer, keep its window(s), display last accessed buffer(s).
  • BufClose not useful because it doesn't work as expected (if you close a buffer that's open in several windows, those windows close).
  • Rewritten Bclose.vim to handle multiple windows.

    vim close all windows but current one

    Bbye Delete buffers and close files in Vim without messing up your window layout.While(l:i 0 & buflisted(prevbufvar) & prevbufvar != s:kwbdBufNum) Are you sure you want to delete it?", "&Yes\n&No", 2) Let answer = confirm("This buffer has been modified. "delete the buffer keep windows create a scratch buffer if no buffers left "here is a more exotic version of my original Kwbd script You can also setup a mapping, see the end of the script. Using this Kwbd command ( :Kwbd) will make Vim windows behave more like an IDE, or maybe even better. The following script ensures this doesn't happen.Įverything in this tutorial assumes the user does "set hidden". Before, if you 1) open vim, 2) :e a file, 3) :bd, 4) :e the same file, then there will be two buffers listed (that file and a buffer). The script, in addition, takes care of a small annoyance. The below script will actually create a scratch buffer if there are no listed buffers left. Let bhidden = filter(copy(blisted), 'bufwinnr(v:val) 0Ĭommand! -bang -complete=buffer -nargs=? Bclose call Bclose(, )īelow, I have a new, more complicated version of above script. Let blisted = filter(range(1, bufnr('$')), 'buflisted(v:val) & v:val != btarget') " Numbers of listed buffers which are not the target to be deleted.

    vim close all windows but current one

    If prevbuf > 0 & buflisted(prevbuf) & prevbuf != btarget " Delete buffer while keeping window layout (don't close buffer's windows).Ĭall s:Warn('Buffer is in multiple windows (use ":let bclose_multiple=1")') Put the following in your vimrc if you would prefer that a buffer is not closed if it is displayed more than once:Ĭreate file ~/.vim/plugin/bclose.vim (Unix) or $HOME/vimfiles/plugin/bclose.vim (Windows) containing the script below, then restart Vim.

    vim close all windows but current one

    You can append ! to discard all changes (for example, :Bclose! will delete the buffer in the current window any changes to the buffer are lost).īy default, :Bclose will close a buffer even if it is displayed in multiple windows (the windows are not closed). Like the :bdelete command, :Bclose will fail if the buffer has been modified. :Bclose Name Close buffer named Name (as shown by :ls).Īssuming the default backslash leader key, you can also press \bd to close (delete) the buffer in the current window (same as :Bclose). :Bclose N Close buffer number N (as shown by :ls).

  • Otherwise, show the previous buffer ( :bprevious), if any.
  • Show the alternate buffer ( :buffer #), if any.
  • For each window where the buffer is currently displayed: The :Bclose command deletes a buffer without changing the window layout.






    Vim close all windows but current one