A better NerdTree setup

Victor Mours
2 min readJun 4, 2015

NerdTree is one of the first plugins you’ll install in Vim. It allows you to browse your files easily and perform some basic operations like creating or moving files without leaving vim.

It’s useful enough to take a minute to set it up properly, yet I often see developers not fully taking advantage of it. Here are a couple of tips to make your NerdTree more awesome:

Open by default

One of the first things I often do when opening a project is taking a look at the file tree to refresh my memory or get the sense of what is happening in a new project. Rather than opening NerdTree manually each time you want to do that, here’s what you can add to your vimrc to open NerdTree when you’re starting vim with no command line arguments (taken from NerdTree’s Readme):

autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists(“s:std_in”) | NERDTree | endif

Finding the right file

You probably already have something similar to this in your .vimrc to open and close NerdTree:

nnoremap <Leader>f :NERDTreeToggle<Enter>

However, you can also directly open NerdTree on the file you’re editing to quickly perform operations on it with NERDTreeFind. Here’s how I recommend adding it to your vimrc:

--

--

Victor Mours

Software engineer. Organizer of the #ParisRubyWorkshop