CtrlP is a file navigation plugin for Vim that supports fuzzy filename matching similar to Command-T, but is written entirely in vimscript. This plugin, CtrlP Generic, is an extension to CtrlP that provides a generic interface to the CtrlP fuzzy matching window. Using this plugin you can support CtrlP style fuzzy selection from any generic list.
The recommended installation for this plugin is via Vundle using the following steps:
- Add the bundle directive to your vimrc after the CtrlP directive as shown below:
- Source the vimrc file to read in the bundle directive
:source $MYVIMRC
- Run the Vundle install command with
:BundleInstall
This will git clone the plugin repository into ~/.vim/bundles, activate the
plugin, and run :helptags
on it. From there you are all set to use it.
Note, since CtrlP-Generic is implemented as an extension to CtrlP, you must also have CtrlP installed and it should appear before CtrlP-Generic in your vimrc:
Sample vimrc:
Bundle "kien/ctrlp.vim"
Bundle "christoomey/ctrlp-generic"
Since CtrlP's match window is asynchronous, CtrlP-Generic requires the use of a
callback function. CtrlPGeneric provides a single function as its interface.
This function, aptly named CtrlPGeneric
, takes two arguments:
- Options - A Vim list containing the items to be selected from
- Callback - The name of the function CtrlP will call with the selected value from the provided Options list.
call CtrlPGeneric(a_vim_list, 'MyGreatCallback')
function! MyGreatCallback(selected_value) range
echo "You selected: " . a:selected_value
endfunction
Callback function notes - The callback function must be glabal and must be defined to accept a range, as shown above.