nvim-compe
Auto completion plugin for nvim.
Table Of Contents
Concept
- Lua source & Vim source
- Better matching algorithm
- Support LSP completion features (trigger character, isIncomplete)
- Effort to avoid flicker
- Respect VSCode/LSP API design
Features
- VSCode compatible expansion handling
- rust-analyzer's Magic completion
- vscode-html-languageserver-bin's closing tag completion
- Other complex expansion are supported
- Flexible Custom Source API
- The source can support
documentation
/resolve
/confirm
- The source can support
- Better fuzzy matching algorithm
gu
can be matchedget_user
fmodify
can be matchedfnamemodify
- See matcher.lua for implementation details if you're interested
- Buffer source carefully crafted
- The buffer source will index buffer words by filetype specific regular expression if needed
Usage
Detailed docs in here
Prerequisite
You must set completeopt
to menu,menuone,noselect
which can be easily done as follows.
Using Vim script
set completeopt=menu,menuone,noselect
Using Lua
vim.o.completeopt = "menu,menuone,noselect"
The enabled
and source
options are required if you want to enable but others can be omitted.
Vim script Config
let g:compe = {}
let g:compe.enabled = v:true
let g:compe.autocomplete = v:true
let g:compe.debug = v:false
let g:compe.min_length = 1
let g:compe.preselect = 'enable'
let g:compe.throttle_time = 80
let g:compe.source_timeout = 200
let g:compe.incomplete_delay = 400
let g:compe.allow_prefix_unmatch = v:false
let g:compe.source = {}
let g:compe.source.path = v:true
let g:compe.source.buffer = v:true
let g:compe.source.calc = v:true
let g:compe.source.vsnip = v:true
let g:compe.source.nvim_lsp = v:true
let g:compe.source.nvim_lua = v:true
let g:compe.source.spell = v:true
let g:compe.source.tags = v:true
let g:compe.source.snippets_nvim = v:true
Lua Config
require'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
min_length = 1;
preselect = 'enable';
throttle_time = 80;
source_timeout = 200;
incomplete_delay = 400;
allow_prefix_unmatch = false;
source = {
path = true;
buffer = true;
calc = true;
vsnip = true;
nvim_lsp = true;
nvim_lua = true;
spell = true;
tags = true;
snippets_nvim = true;
};
}
Mappings
If you don't use any autopair plugin.
inoremap <silent><expr> <C-Space> compe#complete()
inoremap <silent><expr> <CR> compe#confirm('<CR>')
inoremap <silent><expr> <C-e> compe#close('<C-e>')
If you use cohama/lexima.vim
" NOTE: Order is important. You can't lazy loading lexima.vim.
let g:lexima_no_default_rules = v:true
call lexima#set_default_rules()
inoremap <silent><expr> <C-Space> compe#complete()
inoremap <silent><expr> <CR> compe#confirm(lexima#expand('<LT>CR>', 'i'))
inoremap <silent><expr> <C-e> compe#close('<C-e>')
If you use Raimondi/delimitMate
inoremap <silent><expr> <C-Space> compe#complete()
inoremap <silent><expr> <CR> compe#confirm({ 'keys': "\<Plug>delimitMateCR", 'mode': '' })
inoremap <silent><expr> <C-e> compe#close('<C-e>')
Built-in sources
Common
- buffer
- path
- tags
- spell
- calc
Neovim-specific
- nvim_lsp
- nvim_lua