mirror of
https://github.com/preservim/nerdtree.git
synced 2024-11-22 20:05:31 +08:00
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.
This commit is contained in:
parent
334fb0e687
commit
84e7a77a7e
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user