I used Vi for a very long time. And then Vim was created, and I've been using Vim for a long time. I've got a .vimrc that suits my needs and I'm very effective with my use of Vim. I thought I was.
But I've been reading about Vim plugins, and I think I have missed out on a new area of Vim functionality. One plugin that is mentioned a lot is NerdTree - a plugin that allows you to navigate the directory tree and select files. I've managed okay over the years, remembering where my files are, keeping a mental model of my directory tree in my head and using tab completion to load the files I want. But sometimes I just want to be lazy and NerdTree sounds like a pleasant way to be lazy.
I went to install it and I had a lot of problems. I solved my problems eventually and these are my notes.
Because I was starting from scratch, I had to make these preliminary steps:
- Create a directory $HOME/.vim
- Create an environment variable $VIMHOME that points to the directory you just created. (export VIMHOME=$HOME/.vimrc)
- Remember to add that to your .bash_profile too.
Then download the NerdTree plugin (NERD_tree.zip) and install it.
- cd $VIMHOME
- unzip ~/downloads/NERD_tree.zip
- If you had an empty .vim directory before, you will now have three directories in there - doc, nerdtree_plugin and plugin, and each of these will have the NerdTree files in them.
- Start Vim.
- :helptags $VIMHOME/doc
It's now ready for use. To view the help for it, type
To run it, type
Because I'm lazy and don't want to type that much to start NerdTree, I added this to my .vimrc:
map t :NERDTree
and now I can just type and NerdTree will start.
A left pane will open with your directory tree displayed. There are a large number of commands. Press ? (as they advise you at the top) to see the list of commands available to you. You will find that some normal editing commands still work too, even if they aren't listed. It's a nice implementation.
The simplest subset of commands:
- Move around the directory tree with the arrow keys and the Vi direction keys (hjkl).
- o or Enter - open the selected file in a new buffer
- o or Enter - expand or contract the selected directory
- p - go back to the parent directory
- r - refresh the current directory
- q - quit NerdTree
Now there's a lot more plugins for me to experiment with.