Saturday, April 30, 2011

Re: User command with -nargs=1

On 30/04/11 2:42 PM, John Beckett wrote:
> 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=*.

I think it just means that it sees the command as having one single
argument, and the spaces are considered part of it, rather than breaking
it into multiple arguments. This possibly only shows up if you use
<f-args>, as arguments are separated.

Try the following code:

command! -nargs=1 TestOne call Test(<f-args>)
command! -nargs=* TestMany call Test(<f-args>)
function! Test(...)
let n = 1
while n <= a:0
call append('$', 'arg '.n.': '.eval('a:'.n))
let n = n+1
endwhile
endfunction
TestOne a b c d
TestMany a b c d

Ben.

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