0

I am working with a plugin which exposes mappings via <Plug>. For example, let's say it has a mapping for <Plug>XYZCommand. Then, I can put the following in my ~/.vimrc:

nmap a <Plug>XYZCommand

... and the key a will perform the plugin author's intention.

However, let's say I want to augment that mapping with other behaviour, so I want to add keys and/or invoke a function before or after this call to the <Plug> (in the same mapping). Adding keys before the <Plug> does not seem to work as it would with any other keymapping. I assume <Plug> is special. Is there any other way to achieve what I want without modifying the original plugin?

5
  • 1
    Adding keys before the <Plug> does not seem to work Actually it should work. Please, give more info on what you're doing. Though I can guess the leading keys do switch from normal to some other mode.
    – Matt
    Nov 7 '21 at 16:55
  • 1
    You can also invoke <Plug> mappings manually, though I forget if you need execute 'normal' "\<Plug>…" or feedkeys("\<Plug>…"); maybe both work
    – D. Ben Knoble
    Nov 7 '21 at 19:08
  • @Matt apologies, you're quite correct! It does work. I'd tested this earlier, but obviously not thoroughly enough! I can prefix the mapping with extra keys. Nov 7 '21 at 20:57
  • @D.BenKnoble good workaround suggestion! Nov 7 '21 at 20:57
  • 1
    Note that suffixing may be harder. For that reason it is common to see <Plug>(someName) such that suffixing is more viable
    – D. Ben Knoble
    Nov 7 '21 at 22:49

Your Answer

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

Browse other questions tagged or ask your own question.