From e7a666a955cfde1592b8c102fd7a516526916a3c Mon Sep 17 00:00:00 2001 From: Techlive Zheng Date: Sat, 20 Apr 2013 15:09:34 +0800 Subject: [PATCH 1/3] 'NextNormalWindow()' should not count the current normal window --- nerdtree_plugin/vim-nerdtree-tabs.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nerdtree_plugin/vim-nerdtree-tabs.vim b/nerdtree_plugin/vim-nerdtree-tabs.vim index 6c8c916..a1c8427 100644 --- a/nerdtree_plugin/vim-nerdtree-tabs.vim +++ b/nerdtree_plugin/vim-nerdtree-tabs.vim @@ -318,6 +318,12 @@ fun! s:NextNormalWindow() continue endif + " skip current normal window + if l:i == winnr() + let l:i = l:i + 1 + continue + endif + return l:i endwhile return -1 From 659f2927e63a644798d6cbc84fa233e5e77a085e Mon Sep 17 00:00:00 2001 From: Techlive Zheng Date: Sat, 20 Apr 2013 15:11:14 +0800 Subject: [PATCH 2/3] Refactor the behavior of quiting if no more normal window Only take action when we are in NERDTree window, and no more window with normal buffer open. Before quitting Vim, delete the buffer so that the '0 mark is correctly set to the previous buffer. This avoids NERDTree buffer being the last displayed buffer if Vim fails to quit due to the last file in the argument list has not been edited yet. Then quit as usual, we have autocmd nesting open, so the 'quit' will trigger other plugin window's quiting behavior. If we are quiting Vim, our current buffer is successfully reset to the last file buffer, no need to warry about failure. --- nerdtree_plugin/vim-nerdtree-tabs.vim | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/nerdtree_plugin/vim-nerdtree-tabs.vim b/nerdtree_plugin/vim-nerdtree-tabs.vim index a1c8427..bc0ba01 100644 --- a/nerdtree_plugin/vim-nerdtree-tabs.vim +++ b/nerdtree_plugin/vim-nerdtree-tabs.vim @@ -335,8 +335,23 @@ endfun " Close all open buffers on entering a window if the only " buffer that's left is the NERDTree buffer fun! s:CloseIfOnlyNerdTreeLeft() - if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) != -1 && winnr("$") == 1 - q + " Only take action when we are in NERDTree window, and no more window + " with normal buffer open. + if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) == winnr() && s:NextNormalWindow() == -1 + " Before quitting Vim, delete the buffer so that the '0 mark + " is correctly set to the previous buffer. This avoids NERDTree + " buffer being the last displayed buffer if Vim fails to quit + " due to the last file in the argument list has not been edited + " yet. Also disable autocmd on this command to avoid unnecessary + " autocmd nesting. + if winnr('$') == 1 + noautocmd bdelete + endif + " Quit as usual, we have autocmd nesting open, so this command + " will trigger other plugin window's quiting behavior. If we are + " quiting Vim, our current buffer is successfully reset to the + " last file buffer, no need to warry about failure. + quit endif endfun @@ -447,7 +462,7 @@ fun! s:LoadPlugin() autocmd VimEnter * call VimEnterHandler() autocmd TabEnter * call TabEnterHandler() autocmd TabLeave * call TabLeaveHandler() - autocmd WinEnter * call WinEnterHandler() + autocmd WinEnter * nested call WinEnterHandler() autocmd WinLeave * call WinLeaveHandler() augroup END From 9a6ba12287e4ca877ec46983bc8879ea495ccc62 Mon Sep 17 00:00:00 2001 From: Techlive Zheng Date: Sat, 20 Apr 2013 15:14:07 +0800 Subject: [PATCH 3/3] Close the tab page if more than one open instead of quiting vim --- nerdtree_plugin/vim-nerdtree-tabs.vim | 30 +++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/nerdtree_plugin/vim-nerdtree-tabs.vim b/nerdtree_plugin/vim-nerdtree-tabs.vim index bc0ba01..1970dbb 100644 --- a/nerdtree_plugin/vim-nerdtree-tabs.vim +++ b/nerdtree_plugin/vim-nerdtree-tabs.vim @@ -338,20 +338,24 @@ fun! s:CloseIfOnlyNerdTreeLeft() " Only take action when we are in NERDTree window, and no more window " with normal buffer open. if exists("t:NERDTreeBufName") && bufwinnr(t:NERDTreeBufName) == winnr() && s:NextNormalWindow() == -1 - " Before quitting Vim, delete the buffer so that the '0 mark - " is correctly set to the previous buffer. This avoids NERDTree - " buffer being the last displayed buffer if Vim fails to quit - " due to the last file in the argument list has not been edited - " yet. Also disable autocmd on this command to avoid unnecessary - " autocmd nesting. - if winnr('$') == 1 - noautocmd bdelete + if tabpagenr('$') == 1 + " Before quitting Vim, delete the buffer so that the '0 mark + " is correctly set to the previous buffer. This avoids NERDTree + " buffer being the last displayed buffer if Vim fails to quit + " due to the last file in the argument list has not been edited + " yet. Also disable autocmd on this command to avoid unnecessary + " autocmd nesting. + if winnr('$') == 1 + noautocmd bdelete + endif + " Quit as usual, we have autocmd nesting open, so this command + " will trigger other plugin window's quiting behavior. If we are + " quiting Vim, our current buffer is successfully reset to the + " last file buffer, no need to warry about failure. + quit + else + close endif - " Quit as usual, we have autocmd nesting open, so this command - " will trigger other plugin window's quiting behavior. If we are - " quiting Vim, our current buffer is successfully reset to the - " last file buffer, no need to warry about failure. - quit endif endfun