Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

chain complete support

haorenW1025 edited this page Mar 31, 2020 · 7 revisions

Setup Chain Completion

completion-nvim has chain completion support, this is greatly inspired by vim-mucomplete(thanks vigoux for this feature suggestion). In short, you can divide completion sources in group and having ins-completion method as backup completion.

NOTE: If you're using chain completion support, you should check if <c-e> has been mapped to other word in insert mode since this plugin use <c-e> to stop completion when switching between sources, use imap <c-e> to see if it's been mapped, if you're not familiar with <c-e> in complete mode, see help complete_CTRL-E.

  • By default, chain completion list is listed as below, which means you have lsp and snippet in the first completion source, <c-p> in ins-complete as the second source and <c-n> in ins-complete as the third source.
let g:completion_chain_complete_list = [
    \{'ins_complete': v:false, 'complete_items': ['lsp', 'snippet']},
    \{'ins_complete': v:true,  'mode': '<c-p>'},
    \{'ins_complete': v:true,  'mode': '<c-n>'}
\]

Switching between completion list

  • You can switch to next or previous completion source with some mapping, for example
imap <c-j> <cmd>lua require'source'.prevCompletion()<CR> "use <c-j> to switch to previous completion
imap <c-k> <cmd>lua require'source'.nextCompletion()<CR> "use <c-k> to switch to next completion
  • Or if you want to change sources whenever this completion source has no complete item, you can turn on auto changing sources by
let g:completion_auto_change_source = 1

Customization of chain_completion_list

  • You can customize your own chain completion list, for not ins-complete sources, you can choose to put them in the same source or separate them. For example, if you want to separate lsp and snippet into two different source, do it like this
" make sure to specify none-ins_complete sources with 'ins_complete': v:false
let g:completion_chain_complete_list = [
    \{'ins_complete': v:false, 'complete_items': ['lsp']},
    \{'ins_complete': v:false, 'complete_items': ['snippet']},
    \{'ins_complete': v:true,  'mode': '<c-p>'},
    \{'ins_complete': v:true,  'mode': '<c-n>'}
\]
  • You can also use ins-complete sources, possible option to the actual key in vim are listed below.
"c-n" : i_CTRL-N
"c-p" : i_CTRL-P
"cmd" : i_CTRL-X_CTRL-V
"defs": i_CTRL-X_CTRL-D
"dict": i_CTRL-X_CTRL-K
"file": i_CTRL-X_CTRL-F
"incl": i_CTRL-X_CTRL-I
"keyn": i_CTRL-X_CTRL-N
"keyp": i_CTRL-X_CTRL-P
"line": i_CTRL-X_CTRL-L
"spel": i_CTRL-X_s
"tags": i_CTRL-X_CTRL-]
"thes": i_CTRL-X_CTRL-T
"user": i_CTRL-X_CTRL-U
  • If you want to use different chain complete list for different filetypes, you can add the filetype key, but remember to specify the default key for all the other filetypes that are not specified.
let g:completion_chain_complete_list = {
    \ 'vim': [
        \{'ins_complete': v:true,  'mode': '<c-p>'},
        \{'ins_complete': v:true,  'mode': '<c-n>'}
    \],
    \ 'lua': [
        \{'ins_complete': v:true,  'mode': '<c-p>'},
        \{'ins_complete': v:true,  'mode': '<c-n>'}
    \],
    \ 'default': [
        \{'ins_complete': v:false, 'complete_items': ['lsp', 'snippet']},
        \{'ins_complete': v:true,  'mode': '<c-p>'},
        \{'ins_complete': v:true,  'mode': '<c-n>'}
    \]
\}

Clone this wiki locally