Welcome to End Point’s blog

Ongoing observations by End Point people

Vim Plugin Spotlight: CtrlP

When I started using Vim I relied on tree-based file browsers like netrw and NerdTree for navigating a project's files within the editor. After discovering and trying the CtrlP plugin for Vim I found that jumping directly to a file based on its path and/or filename could be faster than drilling down through a project's directories one at a time before locating the one containing the file I was looking for.

After it's invoked (usually by a keyboard shortcut) CtrlP will display a list of files in your current project and will filter that list on the fly based on your text input, matching it against both directory names and file names. Pressing <control-f> with CtrlP open toggles through two other modes: most recently used files, and current buffers. This is useful when you want to narrow down the list of potential matches to only files you have worked with recently or currently have open in other buffers. I use CtrlP's buffer mode to jump between open files so often that I added a custom mapping to invoke it in my .vimrc file:

map <leader>b :CtrlPBuffer

CtrlP has many configuration options that can affect its performance and behavior, and installing additional plugins can provide different matcher engines that search through a directory more quickly and return more relevant results than the default matcher. Alternate matchers I've found include:

Of these, I've had the best luck with FelixZ's ctrlp-py-matcher. It's easy to install, works on most systems without requiring additional dependencies, and manages to be both faster and return more relevant results than the built-in CtrlP matcher.

CtrlP is well documented in both its README (available on its GitHub project page) and its Vim documentation (available with :help ctrlp within Vim). The documentation covers the different commands and configuration options provided by CtrlP but simply installing the plugin and hitting <control-p> on your keyboard is enough to get you started with a faster way to navigate between files in any codebase.


Richard Michael said...

Just FYI, development on the original CtrlP repo, to which you linked, stagnated in 2013.

It has been forked and development is continuing.

Patrick Lewis said...

Thanks Richard, I've updated the post to link to the currently maintained CtrlP repo.