
:max_bytes(150000):strip_icc()/TBE_buffer-56a12eb05f9b58b7d0bcd837.jpg)
As always, C- means to press control and the given key. And you can change split points through ex commands, control commands, and by using your mouse.
MACVIM CHANGE BUFFERS WINDOWS
And you can split windows both vertically (side by side) and horizontally (default). In fact, you can view the same file at different lines in different windows. So you can view multiple files in other "windows" in the same Vim session. In MacVim, you can even access a tiny slice of this through the Apple menu (File -> Split-Open). Just comment out the return and replace the command.A lifechanging feature of Vim for me was the window-splitting feature. If empty(a:bang) & getbufvar(btarget, '&modified')Ĭall s:Warn('No write since last change for buffer '.btarget.' (use :Bclose!)') So I changed the script in 2lines to achieve this: MiniBufExplorer provides this capability with a simple user interfaceįor getting asked what should be done, when a file has been modified I use normally :confirm :bd.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. 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. 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. 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).
