Search code examples
vimvivim-pluginneovim

How to set distinct <leader> for a distinct vim plugin


I have conflicts between the default key mappings of plugin jedi-vim and my customized key mapping.

" I mapped some cscope functions like below
nnoremap <leader>g :cscope find g  <c-r>=expand('<cword>')<cr><cr>
nnoremap <leader>d :cscope find d  <c-r>=expand('<cword>')<cr><cr>

However, this key binding is overridden by the key binding of g:jedi#goto_assignments_command and in g:jedi#goto_command jedi-vim.

I am wondering if it is possible to set a distinct <leader> for jedi-vim only instead of re-mapping conflicted keys.


Solution

  • Apparently jedi-vim doesn't use the canonical <Plug>-mappings, but separate configuration variables. Nonetheless

    let g:jedi#goto_assignments_command = ",g"
    let g:jedi#goto_command = ",d"
    

    in your ~/.vimrc (i.e. before jedi-vim is sourced) should do the trick, and this is what I would recommend.

    Alternative

    The <Leader> key is influenced by the mapleader variable. From :help <Leader>:

    Note that the value of "mapleader" is used at the moment the mapping is defined. Changing "mapleader" after that has no effect for already defined mappings.

    So, you could also solve it this way:

    let mapleader = ','
    runtime! plugin/jedi.vim
    unlet mapleader
    

    Plugin managers or installing as a pack plugin further complicate this, and it changes the ordering of plugin initialization. I do not recommend this.