Skip to main content

Developer Hub

Vim Completion Sources

A focused guide for the vim completion sources stage of extension development. Vim completion sources are runtimepath scripts loaded directly by coc.nvim.

Create a Vim completion source

A Vim plugin can provide completion without a Node.js extension. coc.nvim scans each runtimepath entry for autoload/coc/source/name.vim.

autoload/coc/source/email.vim
1" autoload/coc/source/email.vim
2function! coc#source#email#init() abort
3 return {
4 \ 'priority': 9,
5 \ 'shortcut': 'Email',
6 \ 'triggerCharacters': ['@']
7 \ }
8endfunction
9 
10function! coc#source#email#complete(option, cb) abort
11 let items = ['[email protected]', '[email protected]']
12 call a:cb(items)
13endfunction

Required functions

init() returns source options. complete(option, cb) calls the callback with completion items or v:null. The callback can be asynchronous; synchronous computation blocks Vim.

Source options

Use shortcut, priority, filetypes, firstMatch, triggerCharacters, triggerOnly, and isSnippet to control activation and ranking.

Per-source configuration

Users can override the source with coc.source.email.enable, disableSyntaxes, firstMatch, priority, shortcut, and filetypes. Errors are written to :CocOpenLog.

Optional hooks

  • get_startcol(option) changes the completion start column.
  • on_complete(item) handles the confirmed item.
  • on_enter(option) receives buffer, URI, and language ID.
  • refresh() refreshes source data.

API boundary

Vim sources do not support LSP completion fields such as TextEdit, additionalTextEdits, or command. Use languages.registerCompletionItemProvider() in a Node.js extension for those features.

Vim9script is supported on Vim 9, not Neovim; exported source function names must start with an uppercase letter. For the complete item and option fields, see Custom Completion Sources.