CtrlP plugin for Vim

CtrlP in action
CtrlP in action

CtrlP is the one plugin for Vim that literally changes how and where you use the editor! After you start using it, you will stop changing directories, typing out paths and remembering filenames exactly. Using this plugin, you will just open Vim, press a keyboard shortcut, type a few characters of the filename (fuzzy typing, what you type does not even need to be a substring of the filename or file path!). As you type, CtrlP will show and update a list of what it thinks you want and you choose the matching one by pressing Enter. Believe me, it is magic!

So, CtrlP supports opening files from three lists: files around the current directory, your currently open buffers and from the most recently used (MRU) list of files. MRU is basically all the files you had previously opened with Vim. I find MRU to be the killer application of CtrlP and customize it to be the default list to lookup (see how below).

  • CtrlP can be installed easily from its Github repository here using your favorite Vim plugin manager.

  • Inside Vim, you can invoke the plugin anytime by pressing Ctrl+p. By default, CtrlP allows you to open the files around the current directory. They can be filtered down by typing any part of their filename. As each letter is typed, the list of files displayed grows shorter.

  • If you want to search among MRU or among your open buffers, press Ctrl+f once or twice to switch to those modes. Press Esc at any time to dismiss the CtrlP window. You can see which of the three lists is currently being used at the bottom (see screenshot above).

  • To search in MRU by default, add this line to your .vimrc file:

let g:ctrlp_cmd = 'CtrlPMRU'

Most of the time I am opening previously opened files, so I set this in my vimrc file.

  • To search in buffers by default, add this line to your .vimrc file:
let g:ctrlp_cmd = 'CtrlPBuffer'
  • You cannot move up and down the list of files using the j and k since you need them to type filename characters. Instead you can use Ctrl+j and Ctrl+k to achieve the same. Or you can just keep typing more characters that match the filename you are looking for, so that the list shortens and the correct item comes to the bottom.

Tried with: Vim 7.4 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.