Monday, February 7, 2022

vim9script + map needs ?

I can't find any documentation on precisely this point but I inferred that "<SID>" in the mapping below should not be needed. I hoped that would be true from wording (at :help vim9-differences) like the following, admittedly for an expression mapping. If <SID> is intended as required, perhaps that could be mentioned in the Vim 9 doc.

"When defining an expression mapping, the expression will be evaluated in the context of the script where it was defined."

vim9script
def Toggle(): void
  echo 'TOGGLE'
enddef
def Init(): void
  nnoremap <buffer> <F8> :call <SID>Toggle()<CR>j
  echo 'Press F8 to toggle selection.'
enddef
command! Init call Init()

To test, save the above in a file then enter ':so %' and ':Init'. Then press F8.

If "<SID>" is included, pressing F8 shows "TOGGLE". Otherwise I see "E117: Unknown function: Toggle".

John

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/9bcc4dcf-f0c4-4622-8bfe-4169b29a416en%40googlegroups.com.

No comments: