We can adapt the last example to complete only files listed by git.
command! -nargs=1 -bang -complete=customlist,GitFindComplete
\ GitFind edit<bang> <args>
function! GitFindComplete(ArgLead, CmdLine, CursorPos)
let search_pattern = "*" . a:ArgLead . "*"
let shell_cmd = "git ls-files " . shellescape(search_pattern)
return split(system(shell_cmd), "\n")
Now you can use auto-completion to open the files listed by git:
Note that in a custom completion function, we must do more than simply list the files which could be completed. We must also filter the list relative to the current commandline argument
ArgLead. In this example, we ask
git to do the filtering for us, by passing it the argument wrapped in