Import vim9 script as that and map that.func fails

35 views
Skip to first unread message

N V

unread,
Aug 3, 2022, 4:44:51 AM8/3/22
to vim_use
Hi,

Would import vim9 script as that. It seems to work when I directly call that.foobar.

But how to map the same call in a nnoremapping ?
Thank you
NV


# Imported Functions {{{
import './vimfiles/autoload/nvhelper.vim' as that
nnoremap n n:call that.HLNext(80)<CR>
nnoremap N N:call that.HLNext(80)<CR>

N V

unread,
Aug 3, 2022, 4:57:25 AM8/3/22
to vim_use
# Imported Functions {{{
import autoload 'nvhelper.vim' as that                     SUCEED
call that.HLNext(80)                                                    SUCEED
map foo :call that.HLNext(80)<CR>                          FAILS
var FooFunc = that.HLNext
map foo :call FooFunc(80)<CR>                                 FAILS

N V

unread,
Aug 3, 2022, 5:38:28 AM8/3/22
to vim_use
import autoload 'nvhelper.vim' as that
# nnoremap <F12> <ScriptCmd> that.HLNext(80)<CR>          # SUCCESS
nnoremap <silent> n n:<ScriptCmd> that.HLNext(80)<CR>     # FAILS
nnoremap <silent> N n:<ScriptCmd> that.HLNext(80)<CR>

Bram Moolenaar

unread,
Aug 3, 2022, 5:51:49 AM8/3/22
to vim...@googlegroups.com, N V
Use ":help import-legacy" and then go up a few lines.

--
The term "free software" is defined by Richard M. Stallman as
being software that isn't necessarily for free. Confusing?
Let's call it "Stallman software" then!
-- Bram Moolenaar

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

N V

unread,
Aug 3, 2022, 6:05:05 AM8/3/22
to vim_use
Import is now successfull, what is now wrong is overloading mapping as intended by D.Conway https://www.youtube.com/watch?v=aHm36-na4-4#t6m36s
as this :

# Imported Functions {{{
import autoload 'nvhelper.vim' as that
# nnoremap <F12> <ScriptCmd> that.HLNext(80)<CR>          # CALL SUCCESS
nnoremap <silent> n n:<ScriptCmd> that.HLNext(80)<CR>       # FAILS GOTO NEXT
nnoremap <silent> N N:<ScriptCmd> that.HLNext(80)<CR>



It seems to goto one time to item searched but don't do next jump.

N V

unread,
Aug 3, 2022, 9:31:47 AM8/3/22
to vim_use
Thank you Bram, 
  • I added <ScriptCmd> as described.
  • Can you just look at this gif that shows that I have to source $MYVIMRC to take account an import vim9script, then the function that blink the searched work is working.

Maxim Kim

unread,
Aug 4, 2022, 12:52:50 AM8/4/22
to vim_use
> nnoremap <silent> n n<ScriptCmd>that.HLNext(80)<CR>

remove <silent> to see messages, also `:` is not needed.

Also in the gif you are importing with the full path, not sure if it matters.

среда, 3 августа 2022 г. в 20:31:47 UTC+7, niva...@gmail.com:

N V

unread,
Aug 4, 2022, 3:32:45 AM8/4/22
to vim_use
Thank you Maxim, this is what i've done yesterday.

But it does not solve two problems :
  1. first when I open $MYVIMRC and search for a word as 'import' it does not call imported that.HLNExt func, I HAVE TO SOURCE $MYVIMRC ANOTEHR TIME
  2. then, when I search forward for import it blinks the word occurence searched where cursor is on, then searching backwards with N it seems to work until I attempt to search forward one more time and the blinking feature does not appear anymore.

Maxim Kim

unread,
Aug 4, 2022, 4:07:55 AM8/4/22
to vim_use
Why don't you use `import autoload 'nv-helper.vim' as that` ?

PS, have you ever considered :h hl-CurSearch instead?
It doesn't blink but you can set up a different color for a current search under cursor
Screenshot 2022-08-04 150726.png

четверг, 4 августа 2022 г. в 14:32:45 UTC+7, niva...@gmail.com:

Maxim Kim

unread,
Aug 4, 2022, 4:11:17 AM8/4/22
to vim_use
Also please note that space between n and <scriptcmd> might be something you don't want.
Basically your n mapping does `n` then `<space>` (which is cursor right) and then your scriptcmd...

четверг, 4 августа 2022 г. в 14:32:45 UTC+7, niva...@gmail.com:
Thank you Maxim, this is what i've done yesterday.

N V

unread,
Aug 4, 2022, 4:16:21 AM8/4/22
to vim_use
  • Because it fails, with or without 'as that'.
Capture.PNG

  • the other point : damian conway used matchadd and with this point of implementation, it did not blink too, it simulates blinking feature with same idea you provide.
# https://www.youtube.com/watch?v=aHm36-na4-4#t6m36s
export def HLNext(blinktime: number): number

  echomsg 'HLNext 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 

N V

unread,
Aug 4, 2022, 4:18:35 AM8/4/22
to vim_use
Oh ok thank you Maxim.it solved blinking in forward backward.

But I have always to source $MYVIMRC twice, when I am within it.

N V

unread,
Aug 4, 2022, 4:25:45 AM8/4/22
to vim_use
ok it succeed, was the name of script.

N V

unread,
Aug 4, 2022, 4:29:09 AM8/4/22
to vim_use
stay that, inside $MYVIMRC opened buffer,  I have to source it at less one time manually.

Maby side effect of these autocmd 
        # autowrite autosource
        autocmd! CursorHold    $MYVIMRC w! $MYVIMRC
        autocmd! BufWritePost  $MYVIMRC source $MYVIMRC

Reply all
Reply to author
Forward
0 new messages