1

I am wondering how shall I use tmap along with <Plug>.

Here is a snippet of the context where I am using it:

vim9script 

import autoload "../lib/foo.vim"

noremap <unique> <script> <Plug>DoSomething :call <SID>foo.DoSomething()

if !hasmapto('<Plug>DoSomething') || empty(mapcheck("<F2>", "t"))
    tmap <silent> <F2> <c-w><Plug>DoSomething<cr>
endif

When I use hit <F2>, nothing happens but a sound is emitted.

1 Answer 1

2

So, there are a few issues with your example:

  • the two first lines are irrelevant if you don't also include the content of the imported script, because a) we have no idea what DoSomething() does and b) the rest doesn't use the vim9script syntax anyway,
  • the use of <unique> makes it impossible to iterate while testing,
  • the conditional check is also irrelevant.

Here is an actual minimal reproducible example:

noremap <script> <Plug>DoSomething :echo 'Do something.'
tmap <silent> <F2> <c-w><Plug>DoSomething<cr>

The problem is that your <Plug> mapping is defined for normal mode, visual mode, and operator-pending mode (:help :map) while you are trying to consume it in a terminal mode mapping. Changing it to a terminal mode mapping is an easy fix:

tnoremap <script> <Plug>DoSomething :echo 'Do something.'

Do something.

1
  • is defined for normal mode, visual mode, and operator-pending mode auch!
    – Barzi2001
    Commented May 6, 2023 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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