8

When i check my mappings with

:verb nmap y 

i get:

n  y<C-G>      *@:call setreg(v:register, <SNR>104_recall())<CR>
        Last set from ~/.vim/bundle/vim-fugitive-2.2/plugin/fugitive.vim

I try to unmap it with :unmap y<C-G> and with :unmap y<C-g>, but it has no effect and i get the error E31: No such mapping.

How can i remove this mapping? Why doesn't :unmap y<C-G> work here?

1
  • It turns out there is a related ticket for fugitive plugin.
    – Alexey
    Apr 9 '16 at 21:13
7

It seems the mapping is local to a buffer as it was defined with the argument <buffer>.
When you type :unmap y<C-G>, you ask Vim to unmap a global mapping whose {lhs} is y<C-G>, but there's probably no such global mapping on your system hence the error.

If you want to unmap the local mapping, you have to use the same argument <buffer> which was used to define it: :unmap <buffer> y<C-G>

Edit:

To automate the process you could install an autocmd watching the events VimEnter, BufNewFile and BufReadPost. It would test if the mapping exists if !empty(maparg('y<C-G>', 'n')), before trying to delete it. It could give something like:

augroup custom_fugitive
    autocmd!
    autocmd VimEnter,BufNewFile,BufReadPost * if !empty(maparg('y<C-G>', 'n')) | unmap <buffer> y<C-G>| endif
augroup END

You couldn't write this in your vimrc because the latter is sourced before your plugins which would override anything you do. Instead you would have to write it inside ~/.vim/after/plugin/mappings.vim. The filename (mappings.vim) doesn't matter, only the directory is important (~/.vim/after/plugin/).

Edit 2:

As your last comment says it, it seems there's another way to disable the mapping. fugitive install the mappings <C-R><C-G> and y<C-G> only if g:fugitive_no_maps is different than zero. So if you include let g:fugitive_no_maps=1 inside your vimrc, y<C-G> should not be defined.

1
  • The autocmd solution more or less works (except for the first matched file after lvim). From ~/.vimrc. I don't see why attach to VimEnter event. Also, BufReadPost doesn't seem to be any much better than BufRead. And it makes sense to stress that no trailing spaces after unmap is allowed. Anyways, better solution is to put unmaps into ~/.vim/after/ftplugin/FILETYPE.vim (ft).
    – x-yuri
    Dec 9 '18 at 1:12

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.