Skip to main content
deleted 43 characters in body
Source Link
romainl
  • 42.3k
  • 5
  • 87
  • 118

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.'

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

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.

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.

Here is an actual minimal reproducible example:

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

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

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.

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.

Source Link
romainl
  • 42.3k
  • 5
  • 87
  • 118

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.

Here is an actual minimal reproducible example:

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

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

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.