Nerdtree: NERDTree master opening an existing buffer jumps to different tab

Created on 12 Jun 2012  路  8Comments  路  Source: preservim/nerdtree

I've noticed that the behavior between 4.2.0 and the current master (https://github.com/scrooloose/nerdtree/compare/4.2.0...2cb0fc78fb) changes the behavior of open: if a buffer is open in a different tab, hitting enter on a nerdtree node will jump to the tab with that buffer. Is there anyway to get the 4.2.0 behavior of opening the buffer in the last active window of the current tab?

Most helpful comment

I find this behavior annoying as well: I am using tabs to separate different workspaces, and do not want NERDTree to switch tabs.

According to the help there are only two modes:

    if b:NERDTreeType ==# "primary"
        let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in prev window\n"
    else
        let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in current window\n"
    endif

I have worked around it locally by commenting the code that re-uses windows across tabs: https://github.com/blueyed/nerdtree/commit/b2ec5c96edd5997278299f5705ff32d61c5d564a

It would be nice, if NERDTree would use Vim's switchbuf setting. After all, you may not want to re-use windows in the current tab also.

All 8 comments

That actually sounds like the correct behavior - or it should be the default, yet configurable.

(Sorry for the super long delay, but I accidentally pulled master and noticed this again).

"Open in prev window" is what the help window describes what should do; however, I'm getting the behavior "open in prev window if another tab does not contain a window with the file open, otherwise jump to that window in another tab."

I find this behavior annoying as well: I am using tabs to separate different workspaces, and do not want NERDTree to switch tabs.

According to the help there are only two modes:

    if b:NERDTreeType ==# "primary"
        let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in prev window\n"
    else
        let @h=@h."\" ". g:NERDTreeMapActivateNode .": open in current window\n"
    endif

I have worked around it locally by commenting the code that re-uses windows across tabs: https://github.com/blueyed/nerdtree/commit/b2ec5c96edd5997278299f5705ff32d61c5d564a

It would be nice, if NERDTree would use Vim's switchbuf setting. After all, you may not want to re-use windows in the current tab also.

Any updates on this one. Every time I update to origin/master when updating my vim bundles I get this behavior of tab-jumping and I have to reset to an old commit.

Here is the expected behavior that is not being respected in the docs: https://github.com/scrooloose/nerdtree/blob/master/doc/NERD_tree.txt#L265-L282

Seems to have been addressed in 87b2780.

It wasn't clear to me how to leverage the fix in 87b2780. It looks like I need to override the mapping for g:NERDTreeMapActivateNode but ideally I should be able to set "reuse" via an option.

For now, adding this to .vim/nerdtree_plugin/overrides.py works for me:
```vim
function s:SID()
return matchstr(expand(''), '\zs\d+\ze_SID$')
endfun

let s = '' . s:SID() . '_'

" Mapping Overrides

call NERDTreeAddKeyMap({ 'key': g:NERDTreeMapActivateNode, 'scope': 'FileNode', 'callback': s.'activateFileNode', 'override': 1 })

" Mapping Functions

function! s:activateFileNode(node)
call a:node.activate({'reuse': 'currenttab', 'where': 'p'})
endfunction
```

@adgoudz This worked for me:

let NERDTreeCustomOpenArgs = {'file': {'reuse': 'currenttab', 'where': 'p'}, 'dir': {}}

(and then use custom open <CR>, or do e.g. let NERDTreeMapCustomOpen = 'o')

Sorry, not sure if it's bad etiquette to comment on a closed issue after a billion years, but I googled myself here and this would have helped me 馃槄

Was this page helpful?
0 / 5 - 0 ratings