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:
- Part I: surround.vim - find and edit surrounding parens, quotes, html tags, etc.
- Part II: repeat.vim - repeat the previous surrounding command.
- Part III: matchit.vim - extends the functionality of % key.
- Part IV: snipmate.vim - the best snippet plugin for vim
- Part V: a.vim - quickly change between source and header files (.c/.h).
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:
Here are the basics of how to use the plugin:
- Use the natural vim navigation keys
hjklto navigate the files.
oto open the file in a new buffer or open/close directory.
tto open the file in a new tab.
ito open the file in a new horizontal split.
sto open the file in a new vertical split.
pto go to parent directory.
rto 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 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 want. 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 NERD_tree.zip.
- 2. Extract NERD_tree.zip 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 exploring your files with this awesome plugin and until next time!