commit 84e7a77a7eb0be904bedb594ae3a42820c65137e
parent 334fb0e68797cf56d17db42bf56f39030f226cf8
Author: Martin Grenfell <martin.grenfell@gmail.com>
Date: Fri, 14 Oct 2016 16:34:08 +0100
reuse win trees when editing the same dir again
If you do
```
:edit some/dir/
```
then do the same thing at a later point, then the same nerdtree buffer
will be loaded/shown the second time.
Diffstat:
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim
@@ -13,9 +13,33 @@ endfunction
"FUNCTION: nerdtree#checkForBrowse(dir) {{{2
"inits a window tree in the current buffer if appropriate
function! nerdtree#checkForBrowse(dir)
- if a:dir != '' && isdirectory(a:dir)
- call g:NERDTreeCreator.CreateWindowTree(a:dir)
+ if !isdirectory(a:dir)
+ return
endif
+
+ if s:reuseWin(a:dir)
+ return
+ endif
+
+ call g:NERDTreeCreator.CreateWindowTree(a:dir)
+endfunction
+
+function! s:reuseWin(dir) abort
+ let path = g:NERDTreePath.New(fnamemodify(a:dir, ":p"))
+
+ for i in range(1, bufnr("$"))
+ let nt = getbufvar(i, "NERDTree")
+ if empty(nt)
+ continue
+ endif
+
+ if nt.isWinTree() && nt.root.path.equals(path)
+ exec "buffer " . i
+ return 1
+ endif
+ endfor
+
+ return 0
endfunction
" FUNCTION: nerdtree#completeBookmarks(A,L,P) {{{2