5

I'm learning some Vimscript code from here .

And the next lines will not compile:

function! Mapped(fn ,l)
     let new_list = deepcopy(a:l)
     call map(new_list, string(a:fn) . '(v:val)')
     return new_list
endfunction

When I'm running :source %

I'm getting the following error:

Invalid argument: Mapped(fn, l)

I cant' seem to figure out how.

  • Did you tried calling the function in command line? – SibiCoder Jun 25 '16 at 17:22
  • Yes I'm trying to call this function from command mode and it is resulting in "Unknown function " – Shikloshi Jun 25 '16 at 17:25
  • 1
    You should remove the space between the argument fn and the comma: function! Mapped(fn, l). – user9433424 Jun 25 '16 at 17:28
  • 7
    The space before comma is not accepted. This looks like a bug in the parser, report it to vim_dev. – Sato Katsura Jun 25 '16 at 18:05
  • 2
    @SatoKatsura It's a known problem and mentioned in the help (:h todo (search for function, I even posted a patch about it, but Bram didn't want to included it, since he didn't like the style – Christian Brabandt Jun 26 '16 at 19:38
2

Because of a bug in vim_dev parser, the space before coma is not accepted.

Thus you must use:

function! Mapped(fn,l)
     let new_list = deepcopy(a:l)
     call map(new_list, string(a:fn) . '(v:val)')
     return new_list
endfunction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.