0
votes

I have NERDTREE installed.

If I open up a whole directory with vim . I see the following:

enter image description here

If I open up a specific file in the directory with vim file1.txt, I see the following:

enter image description here

Is there a way to have vim . not open up the file browser twice? I get that it has no specific file to open, but I'd rather have it just open up only the left hand pane and then nothing on the right, instead of having to always manually close the right side.

Here's the relevant section of my .vimrc if that helps

" === Plugins

filetype off
call vundle#begin('$HOME/.vim/bundle')

Plugin 'VundleVim/Vundle.vim' " required
Plugin 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }

call vundle#end()
filetype plugin indent on


" === Auto Commands

autocmd VimEnter * NERDTree                                        " Start NERDTree on startup
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree")
  \ && b:NERDTree.isTabTree()) | q | endif                         " Close NERDTree explore after last window closes

" === Config

let NERDTreeMinimalUI  = 1  " NERDTree Minimal UI
let NERDTreeDirArrows  = 1  " NERDTREE Directional Arrows
let NERDTreeShowHidden = 1   " Show hidden files
1
As Jeremy mentioned in his answer, this happened because you're using an autocmd to flush NerdTree out on Vim startup. If you still want to keep that autocmd part, just start Vim without the . (current directory) option. - Wanda Ichsanul Isra

1 Answers

3
votes

Nerdtree doesn't know what you have open in your main pane. Vim doesn't know what Nerdtree does with its side pane.

If you're only concerned about the situation described where you want to open vim in the current directory, vim (just the command with no arguments) will open up the welcome screen, and Nerdtree with your autocommands will open in the side pane based on the current directory.

If you're concerned about pointing vim at a directory other than cwd, you could disable the Nerdtree plugin autocommands so it doesn't open automatically, or rewrite the autocommand to trigger iff the thing you told vim to open is a file. Something like this?

augroup NerdTree
  autocmd!
  autocmd VimEnter * | if isdirectory(expand("<afile>")) | :NERDTreeToggle | endif
augroup END

Though I can't quite get it to work right. Maybe someone else can play off what I have so far.