> 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
>
Further experiment shows the following difference: with -nargs=1, ":Test
a b" sees one argument, 'a b'; with -nargs=* it sees two, 'a','b'. Try
the following (untested):
command! -nargs=* Type echo List(<f-args>)
function! List(...)
return a:000
enfunction
and try
:Type a b
-- then the same after replacing -nargs=1 by -nargs=*
Best regards,
Tony.
--
"I cannot read the fiery letters," said Frito Bugger in a
quavering voice.
"No," said GoodGulf, "but I can. The letters are Elvish, of
course, of an ancient mode, but the language is that of Mordor, which
I will not utter here. They are lines of a verse long known in
Elven-lore:
"This Ring, no other, is made by the elves,
Who'd pawn their own mother to grab it themselves.
Ruler of creeper, mortal, and scallop,
This is a sleeper that packs quite a wallop.
The Power almighty rests in this Lone Ring.
The Power, alrighty, for doing your Own Thing.
If broken or busted, it cannot be remade.
If found, send to Sorhed (with postage prepaid)."
-- Harvard Lampoon, "Bored of the Rings"
--
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