This article is part of the article series "Vim Plugins You Should Know About."
<- previous article next article ->
Vim Plugins, surround.vim

This is the sixth post in the article series "Vim Plugins You Should Know About". This time I am going to introduce you to a vim plugin called "nerd_tree.vim". It's so useful that I can't imagine working without it in vim.

Nerd Tree is a nifty plugin that allows you to explore the file system and open files and directories directly from vim. It opens the file system tree in a new vim window and you may use keyboard shortcuts and mouse to open files in new tabs, in new horizontal and vertical splits, quickly navigate between directories and create bookmarks for your most important projects.

This plugin was written by Marty Grenfell (also known as scrooloose).

Previous articles in the series:

Ps. Please help me reach 10,000 RSS subscribers. I am almost there. If you enjoy my posts and have not yet subscribed, subscribe here!

How to use nerd_tree.vim?

Nerd Tree plugin can be activated by the :NERDTree vim command. It will open in vim as a new vertical split on the left:

Vim Nerd Tree
A screenshot of Nerd Tree plugin in action.

Here are the basics of how to use the plugin:

  • Use the natural vim navigation keys hjkl to navigate the files.
  • Press o to open the file in a new buffer or open/close directory.
  • Press t to open the file in a new tab.
  • Press i to open the file in a new horizontal split.
  • Press s to open the file in a new vertical split.
  • Press p to go to parent directory.
  • Press r to refresh the current directory.

All other keyboard shortcuts can be found by pressing ?. It will open a special help screen with the shortcut listings. Press ? again to get back to file tree.

To close the plugin execute the :NERDTreeClose command.

Typing :NERDTree and :NERDTreeClose all the time is really inconvenient. Therefore I have mapped the toggle command :NERDTreeToggle to the F2 key. This way I can quickly open and close Nerd Tree whenever I wish. You can also map it to F2 by putting map <F2> :NERDTreeToggle<CR> in your .vimrc file.

How to install nerd_tree.vim?

To get the latest version:

  • 1. Download
  • 2. Extract to ~/.vim (on Unix/Linux) or ~\vimfiles (on Windows).
  • 3. Run :helptags ~/.vim/doc (on Unix/Linux) or :helptags ~/vimfiles/doc (on Windows) to rebuild the tags file (so that you can read :help NERD_tree.)
  • 4. Restart Vim.

Have Fun!

Have fun exploring your files with this awesome plugin and until next time!

This article is part of the article series "Vim Plugins You Should Know About."
<- previous article next article ->


January 18, 2010, 16:07

Thanks a lot for the series, I am the fan of it. Hope next post will be about project (and/or session) ;)

January 18, 2010, 16:17

Andrey, I actually don't use project or session plugins. I haven't found them useful. Maybe I'll give them another try after I run out of plugins to write about. :)

huffer Permalink
January 18, 2010, 16:31

For the guys who used to find it hart to live without Total Commander, Norton Commander, Dos Navigator, Midnight Commander etc. (like myself as you guessed), the vimcommander plugin is a very good alternative imho..

The fact of not needing to leave the editor while still working on some structured folder hierarchy was a turning point plugin discovery for me.
The editor still remains the app in charge (as opposed to using MC as main app and F4-ing your way to edit individual files); I like the nice toggle of the view, I also like the BS key (go up in the hierarchy) that I so much missed from MC, etc.

Well, these were my two (euro)cents...

David Permalink
January 18, 2010, 16:58

Thanks for posting about this. It got picked up on reddit. I've been looking for something like this for a long time. I'll be trying it out. Maybe I can get away from using gedit for editing RoR apps, just for the side-pane!

Bart Permalink
January 18, 2010, 17:14

How can I thank you enough! I love this. Thanks a ton for writing about this. :)
ps: I am already subscribed to your blog. ;)

typedlambda Permalink
January 18, 2010, 17:48

I still don't get what NERDtree gives you what the build in netrw browser does not... (toggle to tree-view [i] ) but i miss many things like rename, delete...

QSDIE Permalink
October 08, 2012, 12:25

Try pressing 'm' in nerdTree. It gives you a menu, which enables you to create/move/rename/delete folders and files. It took me a long time to find out about this menu but I'm very glad I found out about it, saves me a lot of time!

January 18, 2010, 20:02

I use NERDTree as a file explorer and tool to bookmark folders.

When I'm working on software, I run the Project plugin to organize my files. Only problem I find with the project plugin is that it only supports one project file per Vim and doesn't use REGEX (only) for specifying what files should be under a specific heading.

January 18, 2010, 23:09

I use Jamis Buck's fuzzfinder_textmate all the time.

It takes a bit to install but then it does a fuzzy search of the files in your current directory. I find this easier than a project plugin.

Since its a fuzzy search you can type just a few letters of a directory name and then a slash and it'll know what you mean.

david Permalink
January 19, 2010, 13:02

Nice post.
"Press t to open the file in a new tab."yes, this is cool, but I wonder how to switch between these tabs. Any idea?

January 19, 2010, 13:04

david: use :tabn command (or map it to some key combination (like right arrow)).

January 19, 2010, 22:57

Thanks, I really like this series.

Do you know the NERD commenter plugin? It's really good, and does one simple task very well: commenting and uncommenting for many-many languages.

January 20, 2010, 08:56

sztomi, thanks for suggestion. I had heard about NERD commenter but haven't tried it. If it's good I'll make it Part VII in this article series. :)

January 21, 2010, 14:16

Thanks for your articles, they're absolutely great! Nice writing, interesting subjects, valuable info.

I think you've converted me to Vim :).

Cheers from Romania!

February 11, 2010, 10:00

I like session. It is very simple.

March 04, 2010, 23:39

I generally prefer to use Vim's builtin netrw and sessions for FS browsing and project settings. Unless there's a killer feature here, then I don't know why I'd switch. In fact, if it's a killer feature, why not just add it to one of these existing, pre-packaged functionalities? One of the reasons I chose Vim over Emacs is that it did exactly what I needed out of the box, and I'd think others may make the same decision.

JurgyMan Permalink
April 29, 2010, 18:38

I want to do filename editing in vim...
IE, vim .

use vims powerfull editing...
then: wq!

and my filenames have been changed....

whats best approach for that?

Linulin Permalink
May 01, 2010, 19:20

aptitude install moreutils
# be careful not to delete lines if you just want to rename!

Mert Nuhoglu Permalink
June 15, 2010, 10:23

Thank you for this clear article. Even if these things are very simple for advanced vim users, for a newbie like me, this is very helpful.

Best wishes :)

Tech Help Nerd Permalink
June 29, 2010, 17:12

Thanks for the info. I know the information is related to Nerd with the help of this site so thanks.

Lew Permalink
February 08, 2014, 17:51

"Run :helptags ~/.vim/doc (on Unix/Linux)"
What does Run mean?
How/where do I do this?

Leave a new comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "security_161": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.