Vimmers, You Don’t Need NerdTree

Mo Zhu
3 min readFeb 14, 2014

NerdTree is one of the most popular Vim plugins out there. And indeed, I’ve always been a big advocate of it. However, recently, I got rid of it, having discovered a native substitute.

It turns out, Vim has an “explorer mode” or “netrw” already built in with most of NerdTree’s core functionality.

Entering Explorer Mode

To enter explorer mode, enter the command :E and a file tree will appear (Try :Explore if :E doesn’t work). You can navigate this tree using j and k and pressing enter.

Toggling the List Style

Press i to toggle the appearance of the file tree. By default, explorer mode will only show the contents of the current directory. I prefer the NerdTree style to be my default, which can be set by putting this line in your .vimrc file:

# ~/.vimrclet g:netrw_liststyle=3

NerdTree Commands in Explorer Mode

One of the major draws of NerdTree is the m command, which then lets you create a new file, delete a file, or move a file. Furthermore, NerdTree allows you to easily open a file in a new split. Explorer mode also has this capability. They are as follows:

  1. d creates a new directory
  2. % creates and opens a new file
  3. D deletes a directory or file
  4. R renames a file
  5. o opens the file in a horizontal split
  6. v opens the file in a vertical split

Resizing Windows

When you open a file in a split using o or v, the windows will not be equally sized. You can press <c-w=> to resize all windows to be the same.

More Options

There are even more options available for explorer mode. Just hit F1 when you are in it and it will take you to the Vim help chapter dedicated to it.

Making the Transition Easy

Most people have NerdTree mapped to a convenient key. For example, when I hit <space> k, NerdTree comes up. This is much easier than typing :E, which requires some contortion of the hand. Given how much I use the navigator, this inconvenience is non-trivial.

To ween myself off NerdTree, I mapped :E <cr> to my NerdTree mapping.

# ~/.vimrclet mapleader=" "
map <leader>k :E<cr>

Drawbacks

One drawback which I discovered is that explorer mode does not allow for quick navigation. So far, I’ve had to manually press j and k to move up and down. The “-” key does allow you to move up one directory, but it doesn’t work well in my preferred tree view.

Ultimately I find this to be a small price to pay compared to the benefits of using the native app.

Benefits

One of the key benefits of learning Vim is that at any machine you encounter, it is very likely that it has Vim installed. This is extremely powerful as the text editor world becomes increasingly fragmented. However, installing a plugin introduces a dependency into your Vim workflow and dilutes the advantage that Vim near-universality provides. By minimizing the number of plugins, you will be able to reduce these dependencies.

Credits

Many thanks to thoughtbot’s Lisa Sy for inspiring me to get rid of NerdTree. Her original blog post can be found here: http://robots.thoughtbot.com/replacing-nerdtree-with-ctrl-p.

--

--