Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I believe that saginaw is correct. The problem resides in the fact that input() handles completion differently than the command! function. I don't think that the author of the input() function gave much thought to custom completion and only added partial support for it. As saginaw mentions, the intput() function has no -nargs parameter like command!. As a result the ArgLead parameter will always be the whole command line, and consequently the match will always be performed against the whole command line.

Workaround:

One possible solution is to prepend the previously typed arguments for completion. That way when the match is performed it will at least be able to see that the user input matches the predefined completions. I accomplished this in this way:
function! CustomCompletion(argLead, line, pos)
   let argList = split(a:line)
   let returnString = ""
   if     len(argList) == 1
      " This is the first argument so nothing special here

   elseif len(argList) == 2
      " Second argument needs to add first argument to completion
      for item in myCompletionList
         let returnString .= argList[0] . " " . item . "\n"
      endfor
      return returnString

   endif
endfunction

This does work reasonably well. The drawback is that if you have windmenu set, the suggestions include the whole command line which is kind of annoying and hard to see if you have a lot of items.

Example: Whole command line match

At present I see no other alternatives, so this will have to do.

As far as the other issue that saginaw mentioned, that is solved (as he stated) herehere. However, I didn't include it in the code since I didn't think it was relevant to the current problem and would just clutter the example.

I believe that saginaw is correct. The problem resides in the fact that input() handles completion differently than the command! function. I don't think that the author of the input() function gave much thought to custom completion and only added partial support for it. As saginaw mentions, the intput() function has no -nargs parameter like command!. As a result the ArgLead parameter will always be the whole command line, and consequently the match will always be performed against the whole command line.

Workaround:

One possible solution is to prepend the previously typed arguments for completion. That way when the match is performed it will at least be able to see that the user input matches the predefined completions. I accomplished this in this way:
function! CustomCompletion(argLead, line, pos)
   let argList = split(a:line)
   let returnString = ""
   if     len(argList) == 1
      " This is the first argument so nothing special here

   elseif len(argList) == 2
      " Second argument needs to add first argument to completion
      for item in myCompletionList
         let returnString .= argList[0] . " " . item . "\n"
      endfor
      return returnString

   endif
endfunction

This does work reasonably well. The drawback is that if you have windmenu set, the suggestions include the whole command line which is kind of annoying and hard to see if you have a lot of items.

Example: Whole command line match

At present I see no other alternatives, so this will have to do.

As far as the other issue that saginaw mentioned, that is solved (as he stated) here. However, I didn't include it in the code since I didn't think it was relevant to the current problem and would just clutter the example.

I believe that saginaw is correct. The problem resides in the fact that input() handles completion differently than the command! function. I don't think that the author of the input() function gave much thought to custom completion and only added partial support for it. As saginaw mentions, the intput() function has no -nargs parameter like command!. As a result the ArgLead parameter will always be the whole command line, and consequently the match will always be performed against the whole command line.

Workaround:

One possible solution is to prepend the previously typed arguments for completion. That way when the match is performed it will at least be able to see that the user input matches the predefined completions. I accomplished this in this way:
function! CustomCompletion(argLead, line, pos)
   let argList = split(a:line)
   let returnString = ""
   if     len(argList) == 1
      " This is the first argument so nothing special here

   elseif len(argList) == 2
      " Second argument needs to add first argument to completion
      for item in myCompletionList
         let returnString .= argList[0] . " " . item . "\n"
      endfor
      return returnString

   endif
endfunction

This does work reasonably well. The drawback is that if you have windmenu set, the suggestions include the whole command line which is kind of annoying and hard to see if you have a lot of items.

Example: Whole command line match

At present I see no other alternatives, so this will have to do.

As far as the other issue that saginaw mentioned, that is solved (as he stated) here. However, I didn't include it in the code since I didn't think it was relevant to the current problem and would just clutter the example.

Source Link
Tumbler41
  • 7.8k
  • 1
  • 21
  • 48

I believe that saginaw is correct. The problem resides in the fact that input() handles completion differently than the command! function. I don't think that the author of the input() function gave much thought to custom completion and only added partial support for it. As saginaw mentions, the intput() function has no -nargs parameter like command!. As a result the ArgLead parameter will always be the whole command line, and consequently the match will always be performed against the whole command line.

Workaround:

One possible solution is to prepend the previously typed arguments for completion. That way when the match is performed it will at least be able to see that the user input matches the predefined completions. I accomplished this in this way:
function! CustomCompletion(argLead, line, pos)
   let argList = split(a:line)
   let returnString = ""
   if     len(argList) == 1
      " This is the first argument so nothing special here

   elseif len(argList) == 2
      " Second argument needs to add first argument to completion
      for item in myCompletionList
         let returnString .= argList[0] . " " . item . "\n"
      endfor
      return returnString

   endif
endfunction

This does work reasonably well. The drawback is that if you have windmenu set, the suggestions include the whole command line which is kind of annoying and hard to see if you have a lot of items.

Example: Whole command line match

At present I see no other alternatives, so this will have to do.

As far as the other issue that saginaw mentioned, that is solved (as he stated) here. However, I didn't include it in the code since I didn't think it was relevant to the current problem and would just clutter the example.