I have coc.vim installed and added suggested mappings, then I installed vim-fugitive and I want to remap the "Toggle an inline diff of the file under the cursor." fugitive_= to Tab but the coc.vim is using tab for completion.

How I can map the Tab to fugitive_= only when I enter to vim-fugitive :GStatus?


You can use the <buffer> argument to restrict a map to a certain filetype, see :help :map-local for details.

Fugitive's status filetype is fugitive, so you can try:

augroup FugitiveMappings
  autocmd FileType fugitive nmap <buffer> <Tab> =

You can also call the right function instead of mapping <Tab> to = (which I think is what you want to do).

If you have a bunch of Fugitive's related customizations you can put all of them in ~/.vim/ftplugin/fugitive.vim (or $XDG_COFIG_HOME/nvim/init.vim if you use Neovim) as @filbranden suggested. You don't need the auto commands if you use this method

  • 2
    You actually need nmap here to pick up the original = binding (one of those rare cases)
    – D. Ben Knoble
    May 10 '20 at 13:33
  • 3
    Another good advice is to use an ftplugin file such as ~/.vim/ftplugin/fugitive.vim for the nmap command, rather than an autocmd FileType...
    – filbranden
    May 10 '20 at 15:06
  • 2
    @Tae you should maybe put it in a augroup (for those who don't know about it). @filbranden I ever wondered if it was better or more reliable to use ftplugin. To me, it seems to be a hassle to have more files where I can have only one.
    – Biggybi
    May 10 '20 at 17:37
  • 2
    @Biggybi It's a trade-off... You end up with your configs more fragmented, but on the other hand you don't have to deal with messy autocmd's, augroup's, escaping, managing separate autocmd's for the same matches, etc. These days when your vimrc can (should?) live inside ~/.vim and it's easy to manage your whole ~/.vim in git, I think it makes all sense to just use more separate files rather than a single big monolithic config.
    – filbranden
    May 10 '20 at 17:54
  • 1
    @filbranden ftplugin, that's interesting, I will try to look it up. BTW thanks for the suggestion.
    – zer09
    May 11 '20 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.