2 minute read Published:

NERDTree and CtrlP in Vim

Finally carved some time out to tweak how I navigate code in Vim. I’ve had NERDTree installed but because I didn’t spend the time to learn the navigation keys, I ended up falling back on my old method for navigation. After learning the keys I set up a quick way of loading up the tree view (noremap \\ :NERDTreeToggle), and set all my bookmarks and show them by default(let NERDTreeShowBookmarks=1).

CtrlP is a great plugin for when you know your code base. I added a map key to reduce typing (let g:ctrlp_map = '<c-p>') and defaulted to name search instead of path(let g:ctrlp_by_filename = 1).

Integrating these two are where I find the most usefulness. I work with a bunch of branches, some in git and most in accurev. One of the projects I work on is actually buried down in the project structured. Because I have different configurations for projects the “root marker” features of CtrlP is not the best solution. But by having NERDTree change CWD whenever the root tree is changed (let NERDTreeChDirMode=2) and setting CtrlP to search under the current CWD (let g:ctrlp_working_path_mode = 'a'), then all I have to do when starting work on a certain project is to change my working directory (C hotkey in NERDTree or just selecting a bookmark) and CtrlP will automatically search in that project.

(Now I just need to get vim to automatically update saved files to my deployment area.)

.vimrc snippet for CtrlP:

"for CtrlP
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
set wildignore+=\*\\tmp\\\*,\*.swp,\*.zip,\*.exe,\*.class,\*.jar,\*.html,*.xml
let g:ctrlp\_root\_markers = [.acignore, .gitignore]
let g:ctrlp\_working\_path_mode = 'a'
let g:ctrlp\_by\_filename = 1

.vimrc snippet for NERDTree:

" NERDTtree
let NERDTreeBookmarksFile=expand("$HOME/.vim-NERDTreeBookmarks")
let NERDTreeShowBookmarks=1
let NERDTreeChDirMode=2
noremap \\ :NERDTreeToggle