I’m using the Utl plugin for Vim and I’m looking for a method of creating a custom autocomplete function to generate a link to an id tag within the file. The format I want to use is:
:CommandName <file> <id tag in file>
I’d like the function to act like the standard directory completion for the first argument. For the second argument I’d like it to search the file specified in the first argument for all strings beginning with “id=” and return the values.
I’ve copied a similar function out of the main Utl package, but I’ve yet to get close to making it work, it currently looks like this:
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
Has anyone got any ideas?
You can try out frawor. If you install it code will be the following: