Make Nerdtree Use Choosewin On Open File

weilbith

One of my two favorite plugins for vim are NERDTree and ChooseWin. Now I rly like to combine them. In fact I want to adjust NERDTree this way, that when open a file (o) it use ChooseWin to ask the user for a window to show the (new) buffer in. The default behaviour is that NERDTree always use the last active window (except its own).

I already go trough the documentation of NERDTree (cause I guess to create a hook here is a solution), but couldn't find something. The section API sounds interest at first, but doesn't help me.

So I just wanna ask the community if someone is hacky enough to find a solution for this.

weilbith

Solution:

To use the choosewin plugin when open a file with NERDTree, the function activateFileNode() has to be adjusted. The approach is simple: Backup the current window ID, call the choosewin function so select a window, jump back to NERDTree by the stored ID and then open the file as normal. Cause NERDTree always use the last visited window, this solution works.
Saving the window ID and jump back is necessary, cause the following procedure by NERDTree to open the file uses variables which are local to their buffer.

Code

In autoload\nerdtree\ui_glue.vim:

function! s:activateFileNode(node)
    let l:nerdwindow = win_getid()
    call choosewin#start(range(1, winnr('$')))
    call win_gotoid(l:nerdwindow) 
    call a:node.activate({'reuse': 'all', 'where': 'p'})
endfunction


Be aware that this only work, if choosewin is installed. So far I don't have a solution how to check this before. Maybe an update follows.

This solution is also available on my fork. As soon as I fixed this "check if plugin exists", I will open a PR.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related