How to Install and setup CoC for autocompletion in Vim

Smarter Vim autocompletion with CoC featured banner

Typing every variable name in full gets old fast, even in an editor as efficient as Vim. CoC, short for Conquer of Completion, is a Language Server Protocol (LSP) client that brings IDE-style autocompletion to Vim and Neovim through a separate Node.js process. The steps below install it with the vim-plug plugin manager, add language support, and confirm the completion menu actually appears.

The setup has three stages: a plugin manager, the CoC plugin itself, and one CoC extension for each language you write. Before starting, check that your editor meets the current requirements.

Requirements for running CoC

Coc.nvim needs Vim 9.0.0438 or newer, or Neovim 0.8.0 or newer, plus Node.js 22.15.0 or newer. If you are still on plain Vim 8 or an old Node release, upgrade before continuing because the plugin refuses to start otherwise. If you want the smoother scripting experience anyway, see how to install Neovim on Linux, and compare the two editors in this Vim vs Neovim breakdown if you are still deciding.

vim --version | head -1
node --version

The first command prints your Vim version with patch level, and the second prints the Node version. A missing node command means you should follow our guide to installing Node.js on Linux first, which takes a couple of minutes with either nvm or your distribution package manager.

Install a plugin manager in Vim

Vim loads plugins from specific directories under your configuration folder, and managing those files by hand gets tedious quickly. A plugin manager handles downloading, updating, and removing plugins for you. Popular choices include vim-plug, Vundle, and pathogen, and this guide uses vim-plug because its commands map cleanly to what CoC expects.

To install vim-plug, download plug.vim from the official junegunn/vim-plug GitHub repository and place it inside an autoload directory in your Vim configuration folder. Then create the directory structure where plugins will live:

mkdir -p ~/.vim/autoload ~/.vim/plugged
curl -sL https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim \
  -o ~/.vim/autoload/plug.vim

The autoload directory holds plug.vim so Vim can find it at startup, while the plugged directory stores everything you install. The full walkthrough, including update and removal commands, lives in our guide to installing plugins with vim-plug, and our Vundle tutorial covers the alternative if you prefer it.

Install CoC in Vim

Add CoC to your .vimrc between the plug#begin and plug#end lines, then save the file:

call plug#begin('~/.vim/plugged')
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

The release branch matters. It ships prebuilt files inside the repository, so PlugInstall downloads a working plugin directly, and you never run a build step. Pinning the master branch instead requires npm ci on every install and update, which is slower and fails more often.

Restart Vim and run the installer:

:PlugInstall

Vim splits the window, clones the coc.nvim repository into the plugged directory, and prints Done! when finished. Close and reopen Vim (here is a quick reference if you ever get stuck exiting it) so the plugin loads, then confirm it started correctly with :checkhealth if you use Neovim, or by opening any source file and watching for the CoC status entry in your statusline.

Install language servers with CocInstall

CoC by itself provides the framework but no completions. Each programming language needs a CoC extension, which wraps a language server behind the scenes. Install extensions from inside Vim with the CocInstall command:

:CocInstall coc-json coc-tsserver

That pair covers JSON and TypeScript or JavaScript, and it is the combination the project recommends trying first. For other languages, pick the matching extension: coc-python style setups via a language server such as coc-pyright for Python, coc-html and coc-css for front-end work, and coc-sh for shell scripts. Search the full catalog any time with :CocList extensions after installing, or browse the coc.nvim extensions topic on GitHub.

:CocInstall coc-pyright coc-html coc-css coc-sh coc-snippets

Extensions install into the ~/.config/coc/extensions directory and load on the next startup. Removing one later takes a single command, :CocUninstall followed by the extension name.

Configure completion keys in .vimrc

Out of the box, CoC shows the completion menu but leaves navigation keys untouched. Mapping Tab, Shift-Tab, and Enter makes the menu behave the way most editors do. Add this block to your .vimrc, adapted from the official example configuration in the coc.nvim documentation:

" Always show the signcolumn so diagnostics don't shift text
set signcolumn=yes

" Tab moves through the completion menu or falls back to a real tab
inoremap <silent><expr> <TAB>
      \ coc#pum#visible() ? coc#pum#next(1) :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"

" Enter confirms the selected completion item
inoremap <silent><expr> <CR> coc#pum#visible()
      \ ? coc#pum#confirm() : "\<CR>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

The check_back_space function decides whether Tab should trigger a completion attempt or insert a literal tab character, based on whether the cursor follows whitespace. After saving, restart Vim and open a file in a language you installed an extension for.

Type a few letters of a known function or keyword. The completion menu pops up automatically, Tab cycles through candidates, and Enter inserts the selection along with any snippet placeholders the language server provides. The result looks like this:

Vim Autocomplete Setup With CoC
Vim Autocomplete Setup With CoC

This is the end state worth checking against: a popup menu listing candidate completions with their kinds, driven entirely from the language server rather than words already present in the buffer. If nothing appears, run :CocInfo to see whether the Node process launched and which extensions loaded.

Adjust settings with CocConfig

CoC stores per-project and global settings in coc-settings.json, which opens with the :CocConfig command. Two settings cover most customization needs:

{ “suggest.autoTrigger”: “always”, “suggest.maxCompleteItemCount”: 20 }

The first controls when the menu appears without you pressing a key, accepting always, trigger, or none. The second caps the menu length when a common prefix matches many candidates. Edit this file only through :CocConfig, since hand edits can be overwritten while the language server is running.

If you want to go beyond autocompletion, CoC also supplies diagnostics, hover documentation, and code actions, enough to turn Vim into a lightweight IDE without leaving the terminal. The :help coc.txt document inside Vim remains the complete reference. To sharpen the rest of your editing flow, learn how Vim and Neovim registers store your yanks and deletes while you work.

What is CoC and how does it support autocompletion in Vim?

CoC stands for Conquer of Completion. It is an LSP client for Vim and Neovim that runs a Node.js process alongside your editor, so language servers provide intelligent suggestions, diagnostics, and snippet expansion instead of simple word matching.

How do I install CoC for Vim?

Add Plug ‘neoclide/coc.nvim’, {‘branch’: ‘release’} between call plug#begin and call plug#end in your .vimrc, restart Vim, and run :PlugInstall. You need Vim 9.0.0438+ or Neovim 0.8.0+ and Node.js 22.15.0+ beforehand.

Why does my CoC installation ask me to run yarn install?

That happens on the master branch, which has no prebuilt files. Switch to the release branch in your vimrc, run :PlugUpdate, and the build step disappears because the release branch ships compiled output.

How do I get completions for my programming language?

Install the matching CoC extension with :CocInstall, for example coc-tsserver for JavaScript and TypeScript or coc-pyright for Python. Each extension wraps a language server, so completions arrive once the extension loads.

What should I do if CoC is not working as expected?

Run :CocInfo to check the Node.js process and loaded extensions, confirm your Node version meets the minimum, and use :verbose imap to verify another plugin has not stolen your Tab mapping. The coc.nvim wiki also documents common failure modes.

How do I update CoC and its extensions?

Run :PlugUpdate to fetch the latest coc.nvim release build, then :CocUpdate to refresh installed extensions. Both finish in seconds on a normal connection.