Skip to content

Commit 582bb27

Browse files
author
Martin Rubli
committed
Fix focussing previous buffer when closing NERDTree
Previously closing NERDTree while two windows were showing the same buffer would focus the first window, which was not necessarily the previously active one. Instead of obtaining the buffer ID of the previous buffer and mapping that to the window ID (which is a 1:n mapping) we obtain the unique window ID and focus the right window after closing NERDTree. win_getid() and win_gotoid() are available from VIM 7.4.1557, so this patch is conditional on that version.
1 parent 68572ef commit 582bb27

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/nerdtree/nerdtree.vim

+11-3
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,23 @@ function! s:NERDTree.Close()
4040
if winnr("$") != 1
4141
if winnr() == s:NERDTree.GetWinNum()
4242
call nerdtree#exec("wincmd p")
43-
let bufnr = bufnr("")
43+
if v:version > 704 || (v:version == 704 && has('patch1557'))
44+
let l:winid = win_getid()
45+
else
46+
let bufnr = bufnr("")
47+
endif
4448
call nerdtree#exec("wincmd p")
4549
else
46-
let bufnr = bufnr("")
50+
let l:winid = win_getid()
4751
endif
4852

4953
call nerdtree#exec(s:NERDTree.GetWinNum() . " wincmd w")
5054
close
51-
call nerdtree#exec(bufwinnr(bufnr) . " wincmd w")
55+
if v:version > 704 || (v:version == 704 && has('patch1557'))
56+
call nerdtree#exec("call win_gotoid(" . l:winid . ")")
57+
else
58+
call nerdtree#exec(bufwinnr(bufnr) . " wincmd w")
59+
endif
5260
else
5361
close
5462
endif

0 commit comments

Comments
 (0)