Vim:如何拆分命令行参数?
发布时间:2020-12-16 01:50:04 所属栏目:安全 来源:网络整理
导读:根据f-args文档,传递给用户定义函数的命令行参数将自动拆分为空格或制表符,如帮助所示: *f-args*To allow commands to pass their arguments on to a user-defined function,thereis a special form f-args ("function args"). This splits the commandargu
根据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 ab 'ab' XX a b 'a b' XX a b 'a ','b' XX ab 'ab' .... 但是最基本的例子不起作用: 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将其视为一个.为什么会这样? 副问题(它可以以某种方式配置为以逗号分割参数吗?) 解决方法
你指定了-nargs =?.
文件说:
和
(强调我的.) 如果使用-nargs = *,则会获得正常行为. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |