vimnerdtree

Open nerdtree automatically when start vim on a folder and don't show two tree viewers


I would like to open NERDtree automatically but only when passing a folder argument in command line, and that it would not open two tree viewers, only NERDtree. For example, if I am on folder 'rootFolder', which has a 'childFolder' and I run:

nvim childFolder

I would like it to open vim like if I had done:

cd childFolder
nvim
:NERDtree

And if I open a file or empty I would like it to not show nerdtree. That way if I just work on a single file like:

nvim

or

nvim test.js

or

nvim reminder.txt

I don't need to see NERDtree, because I don't need it, it's just a test script or a notes file I am leaving myself.


Solution

  • I found a workaround, add these two lines in .vimrc:

    let g:NERDTreeHijackNetrw = 1
    au VimEnter NERD_tree_1 enew | execute 'NERDTree '.argv()[0]