Skip to content

Using coc extensions

Qiming Zhao edited this page Aug 3, 2026 · 218 revisions

Why are coc extensions needed?

The main reason for having extensions is to achieve a better user experience. Some community-provided language servers are less straightforward and less easy to use than VS Code extensions. Coc extensions can be forked from VS Code extensions and should provide a similar or better user experience.

Compared with configured language servers, extensions support more features.

  • Extensions can contribute properties to the coc-settings.json schema, so like in VS Code you get completion and validation support when you have coc-json installed.

    Screen Shot 2019-06-26 at 3 22 05 PM
  • Extensions can contribute commands (like VS Code). You can use coc commands in different ways:

    • Use the :CocList commands command to open the command list and choose the one you need.

      screen shot 2018-09-07 at 4 53 12 pm
    • Use :CocCommand with <tab> for command line completion.

    • An example configuration that maps the custom command Tsc to tsserver.watchBuild:

      command! -nargs=0 Tsc    :CocCommand tsserver.watchBuild
  • Extensions can contribute JSON schemas (loaded by coc-json).

  • Extensions can contribute snippets that can be loaded by the coc-snippets extension.

  • Extensions can specify additional client options, such as fileEvents for watching files (requires watchman to be installed) and middleware, which can be used to fix results returned from the language server.

For a deeper dive into the purpose and implementation of coc extensions, please see How to write a coc.nvim extension.

Differences between coc extensions and VS Code extensions

  • Coc extensions use coc.nvim as a dependency instead of VS Code.
  • Coc extensions support language server features by using the API from coc.nvim instead of vscode-languageclient, which can only be used with VS Code.
  • Coc extensions support some features of VS Code extensions:
    • activate and deactivate APIs.
    • activationEvents in package.json.
    • Configuration support: contributes.configuration in package.json.
    • Commands support: contributes.commands.
    • JSON validation support via JSON Schema: contributes.jsonValidation.
    • Snippets support.

Manage coc extensions

Single-file extensions

Coc.nvim will try to load JavaScript files from the coc-extensions folder under g:coc_config_home (default ~/.config/nvim). Each JavaScript file should be a coc.nvim extension.

An example coc extension that converts the character at the cursor position to its Unicode code point:

const { commands, workspace } = require('coc.nvim')

exports.activate = context => {
  let { nvim } = workspace
  context.subscriptions.push(commands.registerCommand('code.convertCodePoint', async () => {
    let [pos, line] = await nvim.eval('[coc#util#cursor(), getline(".")]')
    let curr = pos[1] == 0 ? '' : line.slice(pos[1], pos[1] + 1)
    let code = curr.codePointAt(0)
    let str = code.toString(16)
    str = str.length == 4 ? str : '0'.repeat(4 - str.length) + str
    let result = `${line.slice(0, pos[1])}${'\\u' + str}${line.slice(pos[1] + 1)}`
    await nvim.call('setline', ['.', result])
  }))
}

Note: single-file extensions can't be managed by the extensions list. To contribute extension metadata, create a ${name}.json file alongside ${name}.js with activationEvents and contributes properties.

Install extensions

Using :CocInstall:

:CocInstall coc-json coc-css

One or more extension names can be provided.

Note: VS Code extensions can't be used by coc.nvim for now.

Extensions will be loaded and activated after the install succeeds.

Note: you can add extension names to the g:coc_global_extensions variable, and coc will install the missing extensions after the coc.nvim service starts. For example:

let g:coc_global_extensions = ['coc-json', 'coc-git']

To install extensions with a shell script, use a command like:

# install coc-json & coc-html and exit
vim -c 'CocInstall -sync coc-json coc-html|q'

Using custom registry

You can customize the npm registry for coc.nvim by adding coc.nvim:registry to ~/.npmrc:

coc.nvim:registry=https://registry.npmjs.org/

Installing specific versions (for rollback/revert/etc)

If you need to roll back to a specific extension version, or just want to install a particular version, add @version to your install command.

Using coc-prettier as an example, to install version 1.1.17, run:

:CocInstall coc-prettier@1.1.17

Use vim's plugin manager for coc extensions

You can manage coc extensions with a vim plugin manager like vim-plug. Coc will try to load coc extensions from your &rtp.

Example for coc-tsserver:

Plug 'neoclide/coc-tsserver', {'do': 'yarn install --frozen-lockfile'}

After adding this to your vimrc, run PlugInstall.

Note: For coc extensions written in TypeScript, you have to build them when installing from git. Most of the time you should install yarn and run yarn install --frozen-lockfile in the extension root.

The limitation is that you can't uninstall these extensions with :CocUninstall, and automatic updates are not available.

Update extensions

Use the command :CocUpdate or :CocUpdateSync to update extensions installed by :CocInstall to the latest version.

For extensions loaded from vim's rtp, update them with your plugin manager.

To enable automatic updates, set the extensions.updateCheck configuration to "daily" or "weekly" (defaults to "never").

To upgrade extensions with a shell script, use a command like:

vim -c 'CocUpdateSync|q'

Uninstall coc extension

Use the :CocUninstall vim command for extensions installed by :CocInstall, for example:

:CocUninstall coc-css

Manage extensions with CocList

Run :CocList extensions to open the CocList buffer, which looks like:

:CocList extensions
screen shot 2018-09-10 at 10 28 06 pm
  • ? means the extension isn't recognized by coc.nvim
  • * means the extension is activated
  • + means the extension's package.json is loaded, but the extension isn't activated
  • - means the extension is disabled

Supported actions (press <Tab> to open the action menu):

  • toggle (default action): activates/deactivates the selected extension(s).
  • enable: enables the selected extension(s).
  • disable: disables the selected extension(s).
  • reload: reloads the selected extension(s).
  • uninstall: removes the selected extension(s).
  • lock: toggles the lock of an extension; locked extensions won't be updated by :CocUpdate.

Debug coc extension

If an extension throws uncaught errors, you can see the error message with :messages.

For extensions using a language server, you can use the output channel. Check out https://github.com/neoclide/coc.nvim/wiki/Debug-language-server#using-output-channel.

Use console to log messages to coc.nvim's log file; supported methods include debug, log, error, info, and warn. Check out :h :CocOpenLog.

You can also use Chrome to debug extensions; check out https://github.com/neoclide/coc.nvim/wiki/Debug-coc.nvim.

Implemented coc extensions

You can find available coc extensions by searching coc.nvim on npm, or use coc-marketplace, which can search for and install extensions directly in coc.nvim.

Tips: use :CocConfig to edit the configuration file. Completion and validation are supported after coc-json is installed.

REPL

Clone this wiki locally