Let's take a look at the example below.
function! Print (text)
echo a:text
endfunction
function! Mapping_test (parameter)
nnoremap m1 :call Print (a:parameter)<CR>
nnoremap m2 :call Print ("hello")<CR>
execute 'nnoremap m3 :call Print ("' . a:parameter . '")<CR>'
execute 'command! -nargs=0 MTest :call Print ("' . a:parameter . '")'
endfunction
call Mapping_test ("hello world")
m1 mapping produces two errors:
E121: Undefined variable: a:parameter
E116: Invalid arguments for function Print
m2 and m3 work fine. So calling function with string literal is fine, using execute is also ok, but why m1 does not work?
Basically, I could take m3 and be happy, but if I change argument of Mapping_test() from string literal to an array then m3 does not work either.
call Mapping_test (["hello world"])
produces
E730: Using a List as a String
I even tried to use command, but result is the same, when passing List as a:parameter, error occurs.
So, is there any possible way I can pass argument (here a:parameter) to a function call (in a mapping) which type is not a String?