Configuring plugins

Plugins often expose commands for you to map to and variables to change plugin behavior. It's a good idea to review the available options and commands for the plugins you use. Sane plugin defaults make a huge difference in experience. Creating shortcuts that are easy for you to remember will help you remember how to use the plugin you forgot about in a few months.

Vim allows for the creation of global variables, which are primarily used to configure plugins. Global variables are usually prefixed by g:. You can find a list of configuration options in the plugin documentation by running :help <plugin-name> and looking for options.

For example, opening a help file for the CtrlP plugin (by running :help ctrlp) and searching for options (/options) yields the following:

You can read more about the CtrlP plugin under Chapter 2Advanced Editing and Navigation.

If we follow the ctrlp-options link (by pressing Ctrl + ]), we will be taken to a list of available options:

Let's pick an interesting option to explore, say ctrlp_working_path_mode. Move your cursor over to the link, and press Ctrl ] to follow it further:

It looks like this option guards how CtrlP sets a local working directory. If we wanted to change it to look for a root folder of our Git project (with a fallback to the current working directory), we would change our .vimrc file accordingly:

" Set CtrlP working directory to a repository root (with a
" fallback to current directory).
let g:ctrlp_working_path_mode = 'ra'

Digging through the available options for plugins takes time; however, it might make you much more productive or even completely change the way you use the plugins.

Remember the leader key? It comes in very handy with plugins, as it provides a full namespace for plugins to use. Some plugins already use the leader key for their default key bindings, others not so much. You can always make your own easy to remember mappings!

For example, all three CtrlP modes can be easily accessed with two key presses:

" Remap CtrlP actions to be prefixed by a leader key.
noremap <leader>p :CtrlP<cr>
noremap <leader>b :CtrlPBuffer<cr>
noremap <leader>m :CtrlPMRU<cr>

I find it extremely useful to take some time to optimize my key mappings or customize plugin options. Small investment and some mindfulness goes a long way in getting the most out of your setup.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.136.170