Nerdtree: When opening a file Nerdtree disappear (only if i open the file with enter)

Created on 10 Feb 2021  路  9Comments  路  Source: preservim/nerdtree

I'm using Neovim v0.4.4

Basically i configured nerdtree to open in a tab on the left side, using more or less the same configuration i used in other nerdtree installation.

Basically if i try to navigate to the file in the nerdtree pane using keyboard and i open it pressing enter the Nerdtree pane disappear, and i see the message: "Nerdtree: no trees to mirror"

But if i open the same file pressing "o" or "t" or double clicking on it, the tree stays open.

The configuration i'm using is:

autocmd vimenter * NERDTree | wincmd w
autocmd StdinReadPre * let s:std_in=1
autocmd BufWinEnter * NERDTreeMirror
autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | endif
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
autocmd FileType nerdtree let t:nerdtree_winnr = bufwinnr('%')
autocmd BufWinEnter * NERDTreeMirror
" Exit Vim if NERDTree is the only window left.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() |
    \ quit | endif
" Open the existing NERDTree on each new tab.
autocmd VimEnter * NERDTree

" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
    \ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif

autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | wincmd p | ene | exe 'NERDTree' argv()[0] | endif
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
let g:NERDTreeMapOpenInTab = 'o'

I saw that closed issue that could be related to my problem: https://github.com/preservim/nerdtree/issues/145 But unfortunately the link there is no longer active, so i can't try the solution proposed.

I'm using neovim on fedora 33

bug

Most helpful comment

One of the recent pull requests changed the default behavior of the <CR> key. I will fix it, and you can remove the let NERDTreeCustomOpenArgs = ... statement if you prefer. The fix will be out later today.

All 9 comments

Btw i think that the no trees to mirror is not really related to my issue!

I can confirm this bug. Although I do not get the "no trees to mirror" message.

I'm experiencing the same error within NeoVim on macOS. No error messages though.

Try

let NERDTreeCustomOpenArgs = {'file': {'reuse': 'all', 'where': 'p', 'keepopen': 1}, 'dir': {}}

The important option is 'keepopen': 1. The other options are the default values.

See :help NERDTreeCustomOpenArgs

It seems this new behaviour was introduced yesterday but I didn't investigate the actual cause.

Try

let NERDTreeCustomOpenArgs = {'file': {'reuse': 'all', 'where': 'p', 'keepopen': 1}, 'dir': {}}

The important option is 'keepopen': 1. The other options are the default values.

See :help NERDTreeCustomOpenArgs

It seems this new behaviour was introduced yesterday but I didn't investigate the actual cause.

Can confirm this works. Thanks!

Yeah, i too can confirm it works!!
Thanks for the help!

One of the recent pull requests changed the default behavior of the <CR> key. I will fix it, and you can remove the let NERDTreeCustomOpenArgs = ... statement if you prefer. The fix will be out later today.

@dreamos82 The "no trees to mirror" error message you're seeing is caused by your autocommand statement:

autocmd BufWinEnter * NERDTreeMirror

It's an entirely expected message to appear, especially before you've opened any NERDTree, but to get rid of it, change that statement to this:

autocmd BufWinEnter * silent NERDTreeMirror

Thank you @PhilRunninger!

I can confirm that after last pull from git it works even without the .vimrc config line you suggested.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BigfootN picture BigfootN  路  5Comments

kevinSuttle picture kevinSuttle  路  4Comments

fncll picture fncll  路  4Comments

kristijanhusak picture kristijanhusak  路  3Comments

kyoz picture kyoz  路  4Comments