How to add NERDTree to your .vimrc

Viewed 77721

How do I add NERDTree to my .vimrc?

7 Answers

I like to open NERDTree on startup, but with two requirements:

  • Open NERDTree only when there are no arguments (file arguments)
  • Display only the NERDTree window (I don't want to display the main window)

I use this command:

autocmd VimEnter * if !argc() | NERDTree | wincmd p | q | endif

Update (9 Jan 2022)

I've found a more performant way to meet the two requirements I've specified above.

Remove the autocmd, which I've mentioned above, from the .vimrc file. Instead, create an alias like this:

vim() {
  if [ $# -eq 0 ]; then
    /usr/bin/vim ./
  else
    /usr/bin/vim "$@"
  fi
}
Related