Search code examples
vimpluginsremap

How map <leader>char in Vim?


I just installed vim-indent-guides plugin.

The default mapping to toggle the plugin is <Leader>ig and I want to remap this to Ctrl-i.

These are my attempts:

nnoremap <C-i> <leader>ig
nnoremap <C-i> <Leader>ig

I have a similar approach to switch to relative numbers with Ctrl-n and it's working:

nnoremap <C-n> :set relativenumber!<ENTER>

What's wrong with the <Leader> key?


Solution

  • With :noremap, the original mapping isn't considered. Though :noremap is usually preferred to avoid interactions with other mappings, here you do need to allow remapping:

    nmap <C-i> <leader>ig
    

    This plugin offers a <Plug> mapping to facilitate remapping; then, the original <Leader>ig isn't even defined and free for other uses! Therefore, unless you want to have both, prefer this:

    nmap <C-i> <Plug>IndentGuidesToggle
    

    Note: This is all documented by the plugin under :help indent-guides-mappings.