1

I recently became aware of the getcompletion function which can return autocompletion options for a variety of different things (shell commands, vim autocommand events, files, etc.). Many of the types of things that it can autocomplete are not available in insert mode completion (see ins-completion). Is there a way of harnessing getcompletion in insert mode autocompletion?

1

You can set up "user completion" (invoked with in insert mode with Ctrl-XCtrl-U) to do this:

function! CompleteColorschemes(findstart, base)
  if a:findstart
    " locate the start of the word
    let line = getline('.')
    let start = col('.') - 1
    while start > 0 && line[start - 1] =~ '\a'
      let start -= 1
    endwhile
    return start
  else
    " Use getcompletion() to complete colorschemes
    return getcompletion(a:base, 'color')
  endif
endfunction
set completefunc=CompleteColorschemes

This is a slight adaptation of the example given in :help complete-functions.

Omni completion (omnifunc, Ctrl-XCtrl-O) works in the same way, and is intended for filetype-specific completions

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.