From a8c6245057a0600a663a62ff3a53c90f332be8d9 Mon Sep 17 00:00:00 2001 From: Mohamed Boughaba Date: Thu, 2 Nov 2017 13:26:48 +0100 Subject: [PATCH] Merge pull request #756 from mboughaba/master Previously, deleting a file in the NERDTree with "md" would cause a new buffer to be created to fill the window(s) occupied by a buffer on the file. This pull request makes it so that a new buffer is not created. Instead, the next buffer in the buffer list fills the window. Fixes #755. --- nerdtree_plugin/fs_menu.vim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/nerdtree_plugin/fs_menu.vim b/nerdtree_plugin/fs_menu.vim index bdb638e..e48bd81 100644 --- a/nerdtree_plugin/fs_menu.vim +++ b/nerdtree_plugin/fs_menu.vim @@ -55,7 +55,22 @@ function! s:promptToDelBuffer(bufnum, msg) " Is not it better to close single tabs with this file only ? let s:originalTabNumber = tabpagenr() let s:originalWindowNumber = winnr() - exec "tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':enew! ' | endif" + " Go to the next buffer in buffer list if at least one extra buffer is listed + " Otherwise open a new empty buffer + if v:version >= 800 + let l:listedBufferCount = len(getbufinfo({'buflisted':1})) + elseif v:version >= 702 + let l:listedBufferCount = len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) + else + " Ignore buffer count in this case to make sure we keep the old + " behavior + let l:listedBufferCount = 0 + endif + if l:listedBufferCount > 1 + exec "tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':bnext! ' | endif" + else + exec "tabdo windo if winbufnr(0) == " . a:bufnum . " | exec ':enew! ' | endif" + endif exec "tabnext " . s:originalTabNumber exec s:originalWindowNumber . "wincmd w" " 3. We don't need a previous buffer anymore