I have a command line tool that requires three parameters in the form of:
command input1 input2
I'm trying to write a custom complete function that handles completion for different arguments... well, differently.
Determining which argument I'm on and returning a different set of completion options isn't hard; I've got that figured out:
function! CustomCompletion(argLead, line, pos)
let argList = split(a:line)
if len(argList) == 1
" Do completion for arg 1 (the command)
elseif len(argList) == 2
" Do completion for arg 2
elseif len(argList) == 3
" Do completion for arg 3
endif
endfunction
My problem is with the "argLead" variable. :h command-completion-custom
says this:
ArgLead: the leading portion of the argument currently being completed on.
Places Iv'e researched seem to imply that this variable contains the current white-space separated argument that the cursor is on. However whenever I use it, the variable contains the whole command line (spaces and all). Additionally when I press tab after say, the second argument, the tab completion tries to match the whole command line instead just the current argument.
Is there some way to tell the completion function to parse args based on white-space?
Oh, and I'm calling this function in the thrid paramater of input() if that makes any difference.
let user = input("Enter a command\n", "", "custom,CustomCompletion")
Thanks
input()
function, not the completion function. When you write a completion function for a command, you can tell the latter that it must wait for several arguments thanks to the attribute-nargs=+
. I don't think there's something equivalent forinput()
which is probably why it will always send the whole command line as an argument to the completion function. Maybe you could make 3 distinct calls toinput()
: vpaste.net/FovYz and builduser
afterwards.input()
can only complete the whole command line, your completion function will have to return not just the completion of an argument, but the whole command. Besides, at the moment, your completion function chooses which candidates to return based on the number of "words" on the line (if len(argList) == 1
), but to work properly I think it should also take into account the position of the cursor. That problem seems to be solved in the link you gave though.command -complete ...
. Later, I understand this is not the case, and it gets confusing. Can you explain how the tool should be used when it works as expected?add Foo .