Skip to content
Qiming zhao edited this page Jul 27, 2021 · 105 revisions

Coc.nvim is mostly written in TypeScript and runs on Node.js.

Requirements

  • neovim >= 0.4.0 or vim >= 8.0.1453 (run :version or vim --version to checkout your vim version)
  • node >= 12.12

Install Node.js >= 12 on MacOS:

brew install node

Install the latest stable Node.js; may not work on Windows.

curl -sL install-node.now.sh | sh

Note: coc.nvim finds node by calling executable('node') from within vim. Check out :h g:coc_node_path to customize node path.

Install Yarn — required when building from source.

curl --compressed -o- -L https://yarnpkg.com/install.sh | bash

Note: NixOS users must follow these steps:

  1. Install Node.js via nix-env or put it in /etc/nixos/configuration.nix
  2. sudo nixos-rebuild switch

Add coc.nvim to vim's runtimepath

Using vim-plug

Use release branch (recommended):

Plug 'neoclide/coc.nvim', {'branch': 'release'}

Build from source:

Plug 'neoclide/coc.nvim', { 'branch': 'master', 'do': 'yarn install --frozen-lockfile' }

Run command :PlugInstall in your (neo)vim.

Use default release branch (recommended):

use {'neoclide/coc.nvim', branch = 'release'}

Build from source:

use {'neoclide/coc.nvim', branch = 'master', run = 'yarn install --frozen-lockfile'}

Run command :PackerInstall in your (neo)vim.

Using dein.vim

Use release branch (recommended):

call dein#add('neoclide/coc.nvim', { 'merged': 0, 'rev': 'release' })

Build from source:

call dein#add('neoclide/coc.nvim', { 'merged': 0, 'rev': 'master', 'build': 'yarn install --frozen-lockfile' })

Note: When 'merged': 0 not present, coc.nvim not able to start.

Note: Depends on your network and CPU, first build might take a while.

If you have trouble compiling from source when using dein, try these shell commands:

cd ~/.cache/dein/repos/github.com/neoclide/coc.nvim
git clean -xfd
yarn install --frozen-lockfile

Using NeoBundle

Use release branch:

NeoBundle 'neoclide/coc.nvim', 'release'

Using vim8's native package manager

Unzip source code from release branch:

vim8:

mkdir -p ~/.vim/pack/coc/start
cd ~/.vim/pack/coc/start
git clone https://github.com/neoclide/coc.nvim.git --depth=1
git checkout release

neovim:

mkdir -p ~/.local/share/nvim/site/pack/coc/start
cd ~/.local/share/nvim/site/pack/coc/start
git clone https://github.com/neoclide/coc.nvim.git  --depth=1
git checkout release

Check service state

To check and see if the coc.nvim service is running, use command :checkhealth in neovim (not supported by vim); the output looks like:

screen shot 2018-07-08 at 11 02 23 pm

Set g:coc_node_path variable to specify which node executable to start coc.nvim service from.

Another useful command is :CocInfo — use it after the service has started to get some useful information on it.

Install extensions for programming languages you use daily

For example, for generic web-development consider :CocInstall coc-tsserver coc-json coc-html coc-css

For Python3 :CocInstall coc-pyright

For PHP :CocInstall coc-phpls

and so on...

For more information check out Using coc extensions

Add some configuration

Run :CocConfig, which will open main config file ~/.config/nvim/coc-settings.json (empty for new installation). Add empty JSON object (like {}) and add a list of language servers configurations not already covered by existing extensions (e.g. if you already installed coc-pyright, you don't need to add configuration for the pyls server).

For more information check out Using the configuration file

Install watchman for file watching

For features like workspace_didChangeWatchedFiles to work, you will need to install watchman by following https://facebook.github.io/watchman/docs/install.

Watchman works great even when you have multiple (neo)vim instances started in the same directory.

Warning: Don't create .watchmanconfig file in your home directory.

Note: watchman can use a lot of memory! Run watchman watch-del-all in your shell to free some.

Automation script

To set up coc.nvim and extensions faster on different machines, you can use a shell script, for example:

#!/usr/bin/env bash

set -o nounset    # error when referencing undefined variable
set -o errexit    # exit when command fails

# Install latest nodejs
if [ ! -x "$(command -v node)" ]; then
    curl --fail -LSs https://install-node.now.sh/latest | sh
    export PATH="/usr/local/bin/:$PATH"
    # Or use package manager, e.g.
    # sudo apt-get install nodejs
fi

# Use package feature to install coc.nvim

# for vim8
mkdir -p ~/.vim/pack/coc/start
cd ~/.vim/pack/coc/start
curl --fail -L https://github.com/neoclide/coc.nvim/archive/release.tar.gz | tar xzfv -
# for neovim
# mkdir -p ~/.local/share/nvim/site/pack/coc/start
# cd ~/.local/share/nvim/site/pack/coc/start
# curl --fail -L https://github.com/neoclide/coc.nvim/archive/release.tar.gz | tar xzfv -

# Install extensions
mkdir -p ~/.config/coc/extensions
cd ~/.config/coc/extensions
if [ ! -f package.json ]
then
  echo '{"dependencies":{}}'> package.json
fi
# Change extension names to the extensions you need
npm install coc-snippets --global-style --ignore-scripts --no-bin-links --no-package-lock --only=prod

REPL

Clone this wiki locally