根据
f-args
文档,用户定义的函数所传递的命令行参数将自动在空格或制表符处分割,如帮助所示: *<f-args>*
To allow commands to pass their arguments on to a user-defined function, there
is a special form <f-args> ("function args"). This splits the command
arguments at spaces and tabs, quotes each argument individually, and the
<f-args> sequence is replaced by the comma-separated list of quoted arguments.
See the Mycmd example below. If no arguments are given <f-args> is removed.
To embed whitespace into an argument of <f-args>, prepend a backslash.
<f-args> replaces every pair of backslashes (\\) with one backslash. A
backslash followed by a character other than white space or a backslash
remains unmodified. Overview:
command <f-args> ~
XX ab 'ab'
XX a\b 'a\b'
XX a\ b 'a b'
XX a\ b 'a ', 'b'
XX a\\b 'a\b'
....
然而,最基本的示例并不起作用:
function! TestFunc(...)
echo a:0
echo a:000
endfunction
command! -nargs=? TestFunc call TestFunc(<f-args>)
-------------------------------------------------
> :TestFunc foo bar bla bla, fooo
> 1
> ['foo bar bla bla, fooo']
> :TestFunc foo\ bar
> 1
> ['foo\ bar']
我有一堆用空格分隔的参数,但vim只将它视为一个参数。为什么会这样呢?
另外一个问题是(是否可以配置为在逗号处分割参数?)