Friday, April 29, 2011

User command with -nargs=1

I thought defining a user command with '-nargs=1' would mean
that using more than one argument would give an error, however
I can't see a difference between nargs=1 and nargs=*.

command! -nargs=1 Test call Test('<args>')
function! Test(args)
call append('$', 'args: "' . a:args . '"')
endfunction

After sourcing the above:
:new
:Test (E471 Argument required; good)
:Test a (displays 'args: "a"'; good)
:Test a b (displays 'args: "a b"'; bad?)

I thought '-nargs=1' would give "E488: Trailing characters"
if more than one argument, and isn't "a b" two args?

Above tested with Vim 7.3.170 and 7.2.18 on Windows and Linux.

Is this something to do with allowing spaces in file names?

John

--
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

No comments:

Post a Comment