• This repository has been archived on 27/Jan/2022
  • Stars
    star
    1,284
  • Rank 36,300 (Top 0.8 %)
  • Language
    Lua
  • License
    MIT License
  • Created about 4 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Auto completion Lua plugin for nvim

Warning

nvim-compe is now deprecated. Please use nvim-cmp the successor of nvim-compe.

nvim-compe still works but new feature and bugfixes will be stopped.

nvim-compe

Auto completion plugin for nvim.

Table Of Contents

Concept

  • Simple core
  • No flicker
  • Lua source & Vim source
  • Better matching algorithm
  • Support LSP completion features (trigger character, isIncomplete, expansion)
  • 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
  • Better fuzzy matching algorithm
    • gu can be matched get_user
    • fmodify can be matched fnamemodify
    • See matcher.lua for implementation details
  • Buffer source carefully crafted
    • The buffer source will index buffer words by filetype specific regular expression if needed

Usage

Detailed docs in here or :help compe.

Prerequisite

Neovim version 0.5.0 or above.

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.

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.resolve_timeout = 800
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
let g:compe.source.ultisnips = v:true
let g:compe.source.luasnip = v:true
let g:compe.source.emoji = v:true

Lua Config

require'compe'.setup {
  enabled = true;
  autocomplete = true;
  debug = false;
  min_length = 1;
  preselect = 'enable';
  throttle_time = 80;
  source_timeout = 200;
  resolve_timeout = 800;
  incomplete_delay = 400;
  max_abbr_width = 100;
  max_kind_width = 100;
  max_menu_width = 100;
  documentation = {
    border = { '', '' ,'', ' ', '', '', '', ' ' }, -- the border option is the same as `|help nvim_open_win|`
    winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder",
    max_width = 120,
    min_width = 60,
    max_height = math.floor(vim.o.lines * 0.3),
    min_height = 1,
  };

  source = {
    path = true;
    buffer = true;
    calc = true;
    nvim_lsp = true;
    nvim_lua = true;
    vsnip = true;
    ultisnips = true;
    luasnip = true;
  };
}

Mappings

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 })

If you use windwp/nvim-autopairs

inoremap <silent><expr> <C-Space> compe#complete()
inoremap <silent><expr> <CR>      compe#confirm(luaeval("require 'nvim-autopairs'.autopairs_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 })

Highlight

You can change documentation window's highlight group via following.

highlight link CompeDocumentation NormalFloat

Built-in sources

Common

  • buffer
  • path
  • tags
  • spell
  • calc
  • omni (Warning: It has a lot of side-effect.)

Neovim-specific

  • nvim_lsp
  • nvim_lua

External-plugin

External sources

Known issues

You can see the known issues in here.

Note: The next-version means nvim-cmp now.

FAQ

Can't get it work.

If you are enabling the omni source, please try to disable it.

Incredibly lagging.

If you are enabling the treesitter source, please try to disable it.

Does not work function signature window.

The signature help is out of scope of compe. It should be another plugin e.g. lsp_signature.nvim

If you are enabling the treesitter source, please try to disable it.

How to remove Pattern not found?

You can set set shortmess+=c in your vimrc.

How to use LSP snippet?

  1. Set snippetSupport=true for LSP capabilities.

    local capabilities = vim.lsp.protocol.make_client_capabilities()
    capabilities.textDocument.completion.completionItem.snippetSupport = true
    capabilities.textDocument.completion.completionItem.resolveSupport = {
      properties = {
        'documentation',
        'detail',
        'additionalTextEdits',
      }
    }
    
    require'lspconfig'.rust_analyzer.setup {
      capabilities = capabilities,
    }
  2. Install vim-vsnip

    Plug 'hrsh7th/vim-vsnip'

    or snippets.nvim

    Plug 'norcalli/snippets.nvim'

    or UltiSnips

    Plug 'SirVer/ultisnips'

    or LuaSnip

    Plug 'L3MON4D3/LuaSnip'

How to use tab to navigate completion menu?

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
    return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil
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['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['vsnip#jumpable'](-1) == 1 then
    return t "<Plug>(vsnip-jump-prev)"
  else
    -- If <S-Tab> is not working in your terminal, change it to <C-h>
    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})

How to expand snippets from completion menu?

Use compe#confirm() mapping, as described in section Mappings.

How to automatically select the first match?

compe#confirm() with the select option set to true will select the first item when none has been manually selected. For example:

vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm({ 'keys': '<CR>', 'select': v:true })", { expr = true })

ESC does not close the completion menu

Another plugin might be interfering with it. vim-autoclose does this. You can check the mapping of <ESC> by running

imap <ESC>

vim-autoclose's function looks similar to this:

<Esc> *@pumvisible() ? '<C-E>' : '<C-R>=<SNR>110_FlushBuffer()<CR><Esc>'

In the particular case of vim-autoclose, the problem can be fixed by adding this setting:

let g:AutoClosePumvisible = {"ENTER": "<C-Y>", "ESC": "<ESC>"}

Other plugins might need other custom settings.

Demo

Auto Import

auto import

LSP + rust_analyzer's Magic Completion

lsp

Buffer Source Completion

buffer

Calc Completion

calc

Nvim Lua Completion

nvim lua

Vsnip Completion

vsnip

Snippets.nvim Completion

snippets.nvim

Treesitter Completion

treesitter.nvim

Tag Completion

tag

Spell Completion

spell

More Repositories

1

nvim-cmp

A completion plugin for neovim coded in Lua.
Lua
7,735
star
2

cmp-nvim-lsp

nvim-cmp source for neovim builtin LSP client
Lua
1,184
star
3

vim-vsnip

Snippet plugin for vim/nvim that supports LSP/VSCode's snippet format.
Vim Script
872
star
4

cmp-nvim-lsp-signature-help

cmp-nvim-lsp-signature-help
Lua
585
star
5

cmp-path

nvim-cmp source for path
Lua
581
star
6

cmp-buffer

nvim-cmp source for buffer words
Lua
570
star
7

vscode-langservers-extracted

vscode-langservers bin collection.
Shell
560
star
8

cmp-cmdline

nvim-cmp source for vim's cmdline
Lua
514
star
9

cmp-nvim-lua

nvim-cmp source for nvim lua
Lua
308
star
10

cmp-nvim-lsp-document-symbol

nvim-cmp source for textDocument/documentSymbol via nvim-lsp.
Lua
179
star
11

nvim-insx

Flexible key mapping manager.
Lua
173
star
12

cmp-emoji

nvim-cmp source for emoji
Lua
170
star
13

cmp-calc

nvim-cmp source for math calculation
Lua
142
star
14

cmp-copilot

copilot.vim source for nvim-cmp
Lua
129
star
15

vim-vsnip-integ

vim-vsnip integrations to other plugins.
Vim Script
125
star
16

nvim-pasta

The yank/paste enhancement plugin for neovim.
Lua
103
star
17

cmp-vsnip

nvim-cmp source for vim-vsnip
Lua
90
star
18

vim-searchx

The extended search motion.
Vim Script
76
star
19

vim-eft

enhanced f/t
Vim Script
75
star
20

cmp-omni

nvim-cmp source for omnifunc
Lua
43
star
21

nvim-gtd

LSP's Go to definition plugin for neovim.
Lua
36
star
22

vim-seak

search + seek = seak. The plugin that enhances the `/` and `?`.
Vim Script
35
star
23

js-co-on

co based event emitter handling.
JavaScript
33
star
24

vim-lamp

๐Ÿ’กLanguage Server Protocol client for Vim.
Vim Script
32
star
25

nvim-kit

My personal Lua utilities for neovim.
Lua
27
star
26

nvim-automa

Automatic macro recorder for neovim.
Lua
21
star
27

nvim-dansa

Guess the indent from lines of around.
Lua
19
star
28

vim-vital-vs

Vim Script
18
star
29

denops-popup

https://deno.land/x/denops_popup
Vim Script
17
star
30

vim-gindent

General indentexpr plugin for vim and nvim.
Lua
17
star
31

nvim-lua-rpc-example

Lua
16
star
32

nvim-linkedit

Lua
14
star
33

nvim-automa-poc

POC of plugin that will be called `nvim-automa`
Lua
13
star
34

vim-candle

Candidates listing engine for vim/nvim built on yaegi on golang.
Vim Script
12
star
35

nvim-matcha

A fuzzy finding plugin for neovim (for my personal use)
11
star
36

cmp-core-example

Lua
11
star
37

nvim-lua-rpc-example-with-headless

Use nvim --headless for asynchronous processing
Lua
11
star
38

vim-neco-calc

neocomplcache/neocomplete/deoplete calculates plugin.
Vim Script
10
star
39

vim-versions

useful interface for version control.
Vim Script
9
star
40

vim-compete

Auto completion plugin for vim/nvim that supports fuzzy match.
Vim Script
9
star
41

state-use

Simple state manager for React
TypeScript
8
star
42

deno-json-rpc

Strongly typed json-rpc module for deno.
TypeScript
7
star
43

nvim-plugin-template

Makefile
7
star
44

srimmer

Srimmer provides simple api to use react and immer.
TypeScript
6
star
45

vim-unmatchparen

highlight unmatch parens.
Vim Script
6
star
46

vim-denite-gitto

denite with vim-gitto
Python
6
star
47

msw-snapshot

Transparently create an API cache for testing.
TypeScript
5
star
48

deno-nvim-types

The Nvim API type definition for TypeScript.
TypeScript
5
star
49

completion-snippet

The vim-vsnip snippet collection for completion.
5
star
50

vim-foolish-move

Vim Script
5
star
51

fern-mapping-collapse-or-leave.vim

Vim Script
5
star
52

hrsh7th

My profile.
4
star
53

deoplete-vim-lsc

deoplete source for vim-lsc.
Vim Script
4
star
54

fern-mapping-call-function.vim

Vim Script
4
star
55

vim-aim

This plugin provides motion that similar to /. (experimental)
Vim Script
3
star
56

vim-minx

Extended insert-mode mapping manager.
Vim Script
3
star
57

js-gulp-component-build

gulp plugin to build component.
JavaScript
3
star
58

js-modelis

Modelis javascript modeling support.
JavaScript
2
star
59

vim-lamp-extensions

Vim Script
2
star
60

node-monores

monorepo scripts.
TypeScript
2
star
61

nvim-tuil

nvim plugin utilities that can be embed your plugin.
Lua
2
star
62

frontend-testing-demo

https://hrsh7th.github.io/frontend-testing-demo/main/storybook
TypeScript
2
star
63

vim-compete-lamp

Vim Script
2
star
64

vim-gitto

vim-gitto
Vim Script
2
star
65

vsnip-snippet-plugin-demo

Vim Script
1
star
66

vim-neco-snippets

neocomplcache my snippets.
1
star
67

vim-feeling-move

Vim Script
1
star
68

deoplete-lamp

deoplete source for vim-lamp.
Vim Script
1
star
69

denite-converter-prioritize-basename

Python
1
star
70

denops-sandbox

TypeScript
1
star
71

compe-lamp

vim-lamp source for compe for my personal use.
Vim Script
1
star
72

deoplete-calc

calculates at completion.
Python
1
star
73

nvim-lapi

1
star
74

js-modelis-assurance

assucrance plugin for modelis.
JavaScript
1
star
75

refnew-react

refnew react binding.
TypeScript
1
star
76

deoplete-fname

filename completion for deoplete.nvim.
Python
1
star
77

vim-diffkit

Buffer diff management in VimL. Improve performance for getting buffer's diff.
Vim Script
1
star
78

vim-picka

Vim Script
1
star
79

asyncomplete-lamp

asyncomplete source for vim-lamp.
Vim Script
1
star
80

react-inview-hook

react hooks & intersection-observer
TypeScript
1
star
81

vim-locon

local config in vimrc.
Vim Script
1
star
82

vim-compete-omnifunc

Vim Script
1
star
83

vim-vital-deno

vim x deno (experimental)
1
star
84

diagnostics.nvim

Experimental diagnostics service for neovim.
Vim Script
1
star
85

immer-deps

Auto update dependencies, when immer's produce.
TypeScript
1
star
86

vim-effort-gf

Vim Script
1
star
87

sandbox

Lua
1
star
88

slow-lsp-demo

TypeScript
1
star
89

vim-compete-lsp

vim-lsp source for vim-compete.
Vim Script
1
star
90

xhr-snapshot

TypeScript
1
star
91

refnew

proxy based state management utility.
TypeScript
1
star
92

compe-conjure

compe-nvim source for conjure
Lua
1
star
93

babel-plugin-tree-shakable

good manner cjs files to mjs. this is very very experimental. do not use.
JavaScript
1
star