【发布时间】:2011-11-05 03:12:29
【问题描述】:
我正在使用 Vim 的 Utl 插件,我正在寻找一种方法来创建自定义自动完成功能以生成指向文件中 id 标记的链接。我要使用的格式是:
:CommandName <file> <id tag in file>
我希望函数的作用类似于第一个参数的标准目录完成。对于第二个参数,我希望它在第一个参数中指定的文件中搜索所有以“id=”开头的字符串并返回值。
我已经从主 Utl 包中复制了一个类似的功能,但我还没有接近让它工作,它目前看起来像这样:
fu! CompleteArgs(dummy_argLead, cmdLine, dummy_cursorPos)
" Split cmdLine to figure out how many arguments have been provided by user
" so far. If Using argument keepempty=1 for split will provide empty last
" arg in case of a new arg is about to begin or an non empty last argument
" in case of an incomplete last argument. So can just remove the last arg.
exe "echo \"cmdline:\" \"".a:cmdLine."\""
let utlArgs=split(a:cmdLine, '\s\+', 1)
execute "echo" string(utlArgs)
echo "echo" "test complete"
"remove the function name
call remove(utlArgs, -1)
" 1st arg to complete
if len(utlArgs)==1
return string(glob("*"))
endi
" 2nd arg to complete
if len(utlArgs)==2
"insert code here
endif
endfun
有人有什么想法吗?
【问题讨论】:
标签: function vim autocomplete arguments