Articles

NERDTree

"The NERD tree allows you to explore your filesystem and to open files and directories. It presents the filesystem to you in the form of a tree which you manipulate with the keyboard and/or mouse. It also allows you to perform simple filesystem operations."

I just finished watching Derek Wyatt's videos on VIM and he mentioned a plugin call NERD Tree. I thought I would give you a quick run down of how to install and how to use it. The version we will be talking about today is 4.2.0.

Install:

pathogen.vim

pathogen.vim is the recommended way to install NERD Tree. So lets talk about that first. Basically pathogen.vim is a super easy way to install plugins and runtimes files. Just copy all three lines and paste this into you terminal.

mkdir -p ~/.vim/autoload ~/.vim/bundle; \
curl -so ~/.vim/autoload/pathogen.vim \
    https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim

Now you need to add this little line to your vimrc

vim ~/.vimrc

Add this:

call pathogen#infect()

This should work, if not please review the README doc on github for other examples. https://github.com/tpope/vim-pathogen

NERD Tree

Now that we have pathogen.vim installed it will real easy to install NERD Tree. Just run this line.

cd ~/.vim/bundle

Now all we have to do is a clone from git

git clone https://github.com/scrooloose/nerdtree.git

And there you have it.

Shortcuts

Now that we have everything install, how do we get around and make it work.

:NERDTreeToggle Toggles the vertical NERDTree window on and off.

But honestly, that can be a bunch to typing if you are using it a lot. So lets make a shortcut I learned from Eamon O'Connell. We are going to need to edit our vim config file for this. http://programming34m0.blogspot.com/2011/04/nerd-tree-file-explorer-with-mac-vim.html

vim ~/.vimrc

Add this:

" Give a shortcut key to NERD Tree
map <F2> :NERDTreeToggle<CR>

Great, now we no long have to type :NERDTreeToggle every time, we just have to hit fn+F2.

Now some shortcuts to get you on your way.

Getting around the directory

h j k l navigates around the document

Lets open some windows

s open new vertical split window
i open new horizontal spilt window

The next question I had was how do I switch back and forth between NERDTree and the other windows. All window commands start with ctrl+w

ctrl+ww cycle though all windows
crtl+wh takes you left a window
crtl+wj takes you down a window
crtl+wk takes you up a window
crtl+wl takes you right a window

Lets open some tabs

t open new tab
T open new tab while staying in current tab
gt cycle though all tabs
gT cycle though all tabs (moves to the left)

To close any of these tabs to windows you can get out the same way you do in vim.

:q quit
:wq write (save) and quit

Here is some extras shortcuts and enhancements for NERDtree. These will need to go into you .vimrc file.

vim ~/.vimrc

Then add this to the file.

"Show hidden files in NerdTree
let NERDTreeShowHidden=1

"autopen NERDTree and focus cursor in new document
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p

For some other awesome vim configuration checkout "The ultimate Vim configuration" by amix.