I want to remap <c-b> to foo<c-b>, being foo a number. However, it seems it won't work with function local variables.
For instance, the following works:
vim9script var foo = 4 if !hasmapto('<c-f>', 'n') nnoremap <expr> <c-f> repeat('<c-f>', foo) endif but the following does not work:
vim9script def Func() var foo = 4 if !hasmapto('<c-f>', 'n') nnoremap <expr> <c-f> repeat('<c-f>', foo) endif enddef Func() Is there any reason for it?
:varis not a command, do you intend to use:letas inlet foo = 4instead? I do see an errorE116: Invalid arguments for function repeatiffoohasn't been defined, but as long as the variable is properly defined your second example (which is correct, using<expr>) should work as intended. I'll go ahead and recommend you might want to read Learn Vimscript the Hard Way if you'd like to get more familiar with Vimscript the language and be able to troubleshoot issues like this on your own.varis used in Vim9 to define script-local variables.