Auto completion plugin for nvim.
- Simple core
- No flicker
- Lua source & Vim source
- Better matching algorithm
- Support LSP completion features (trigger character, isIncomplete, expansion)
- Respect VSCode/LSP API design
- 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
- Buffer source carefully crafted
- The buffer source will index buffer words by filetype specific regular expression if needed
Detailed docs in here or :help compe
.
Neovim version 0.5.0 or above (not released yet, use nightlies or build from source).
You must set completeopt
to menuone,noselect
which can be easily done
as follows.
Using Vim script
set completeopt=menuone,noselect
Using Lua
vim.o.completeopt = "menuone,noselect"
The source
option is required if you want to enable but others can be omitted.
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.max_abbr_width = 100
let g:compe.max_kind_width = 100
let g:compe.max_menu_width = 100
let g:compe.documentation = v:true
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.nvim_lsp = v:true
let g:compe.source.nvim_lua = v:true
let g:compe.source.vsnip = v:true
require'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
min_length = 1;
preselect = 'enable';
throttle_time = 80;
source_timeout = 200;
incomplete_delay = 400;
max_abbr_width = 100;
max_kind_width = 100;
max_menu_width = 100;
documentation = true;
source = {
path = true;
buffer = true;
calc = true;
nvim_lsp = true;
nvim_lua = true;
vsnip = true;
};
}
inoremap <silent><expr> <C-Space> compe#complete()
inoremap <silent><expr> <CR> compe#confirm('<CR>')
inoremap <silent><expr> <C-e> compe#close('<C-e>')
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
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>')
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
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>')
inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })
inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })
You can change documentation window's highlight group via following.
highlight link CompeDocumentation NormalFloat
- buffer
- path
- tags
- spell
- calc
- omni (Warning: It has a lot of side-effect.)
- nvim_lsp
- nvim_lua
- vim_lsp
- vim_lsc
- vim-vsnip
- ultisnips
- snippets.nvim
- luasnip
- nvim-treesitter (Warning: it sometimes really slow.)
If you are enabling the omni
source, please try to disable it.
If you are enabling the treesitter
source, please try to disable it.
You can set set shortmess+=c
in your vimrc.
-
Set
snippetSupport=true
for LSP capabilities.local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.textDocument.completion.completionItem.snippetSupport = true require'lspconfig'.rust_analyzer.setup { capabilities = capabilities, }
-
Install
vim-vsnip
Plug 'hrsh7th/vim-vsnip'
or
snippets.nvim
Plug 'norcalli/snippets.nvim'
Tab
and S-Tab
keys need to be mapped to <C-n>
and <C-p>
when completion
menu is visible. Following example will use Tab
and S-Tab
(shift+tab) to
navigate completion menu and jump between
vim-vsnip placeholders when possible:
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local check_back_space = function()
local col = vim.fn.col('.') - 1
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
return true
else
return false
end
end
-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-n>"
elseif vim.fn.call("vsnip#available", {1}) == 1 then
return t "<Plug>(vsnip-expand-or-jump)"
elseif check_back_space() then
return t "<Tab>"
else
return vim.fn['compe#complete']()
end
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
return t "<Plug>(vsnip-jump-prev)"
else
return t "<S-Tab>"
end
end
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
Use compe#confirm()
mapping, as described in section Mappings.