pb with nnoremap an imported vim9 defnot loaded

7 views
Skip to first unread message

Nicolas

unread,
Oct 31, 2022, 1:43:28 AM10/31/22
to vim_use
Hi,


Using this def func to blink searched word I mapped it in $MYVIMRC as this but it seems that at vim startup, the nnoremap is not defined, no call occurs.

Thankyou for help
Nicolas

$MYVIMRC
import autoload './vimfiles/plugged/foobar.vim'
as thatHelp

nnoremap n   n<ScriptCmd> thatHelp.HLNext(80)<CR>
nnoremap N   N<ScriptCmd> thatHelp.HLNext(80)<CR>



foobar.vim
export def HLNext(blinktime: number): number
    # https://www.youtube.com/watch?v=aHm36-na4-4#t6m36s

  echomsg 'export def HLNext has been called.'

  highlight BlackOnBlack guibg=black guifg=#3c4c55 ctermbg=black ctermfg=black

  var [bufnum: number, lnum: number, col: number, off: number] = getpos('.')
  var target_pat: string = '\k*\%#\k*'
  target_pat = '\%#' .. @/
  target_pat = '\k*\%#\k*'
  var blinks: number = 3

  var sleep_duration: number = ( blinktime / (2 * blinks) )->float2nr()
  var sleep_cmd: string = 'sleep ' .. sleep_duration .. 'm'


  for n in range(1, blinks)

    # echomsg n
    var hide: number = matchadd('BlackOnBlack', target_pat, 101)
    redraw
    exec sleep_cmd
    matchdelete(hide)
    redraw
    exec sleep_cmd

  endfor

  return 0

enddef



Salman Halim

unread,
Oct 31, 2022, 10:16:52 AM10/31/22
to vim...@googlegroups.com
Did you type the mappings in the email message or did you copy/paste them from your VIMRC? Are you able to get the mappings to work if you copy/paste them onto the command-line after Vim has started? The primary problem I can see with the mappings is that you have them defined as n<ScriptCmd> instead of just n:

...n<ScriptCmd> th... defines a mapping for n<ScriptCmd>
...n <ScriptCmd>th... defines a mapping for n that then executes a script command and is probably what you want

As an aside, the function you defined is technically correct, though inefficient in a few things, but that's not likely to be the cause of your woes.

--
--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/f6861e1f-9783-49b6-b151-b6f1625e6ce5n%40googlegroups.com.


--
 
Salman

I, too, shall something make and glory in the making.

Nicolas

unread,
Oct 31, 2022, 11:03:23 AM10/31/22
to vim_use
Hi Salman,

I copy paste this from $MYVIMRC
nnoremap n n<ScriptCmd> thatHelp.HLNext(80)<CR>
nnoremap N N<ScriptCmd> thatHelp.HLNext(80)<CR>


I cannot or don"'t know how to test it through command line because it calls an imported vim9 def func.
Reply all
Reply to author
Forward
0 new messages