NERD Tree Guide
The NERD Tree (GitHub: scrooloose / nerdtree) by Martin Grenfell is a popular file system browser. If you’re using it simply to browse and select files like a typical GUI IDE, then it’s worth spending a bit of time going over the documentation, because this plugin does a lot more than displaying a tree of files and directories.
With that in mind, here’s a guide to my favourite features and keyboard commands.
Mirroring
If you want the tree to appear in the same state across multiple tabs, then type :NERDTreeMirror
. Any subsequent changes will be reflected in each mirrored instance. This gives the feel of a traditional IDE, but be wary of relying on it too much -- trying to use tabs this way is seen as somewhat of an anti-pattern.
Keyboard Commands
Type :help NERDTreeMappings
to read through all of the default keyboard shortcuts. These are the ones I use the most frequently:
t
: Open the selected file in a new tabi
: Open the selected file in a horizontal split windows
: Open the selected file in a vertical split windowI
: Toggle hidden filesm
: Show the NERD Tree menuR
: Refresh the tree, useful if files change outside of Vim?
: Toggle NERD Tree's quick help
The NERD Tree Menu
Typing m
will display a menu that allows file system operations to be performed from within NERD Tree. If you need to create a new file or directory, then ma
will show a prompt that allow a file name to be entered.
I find there are cases where NERD Tree’s visual representation of the file system can aid understanding of a project’s structure, so it can be useful to create new files from within it.
Further Reading
Dig into that :help NERDTree
help file and have a look at the options for customisation. And keep your NERD Tree up to date! This plugin has had lots of contributors, and it was updated as recently as two weeks ago.