Skip to main content
Docs / CORE FEATURES

Using Extensions

Install, update, pin, trust, and troubleshoot coc.nvim extensions, including registry choices, plugin-manager installs, and schema-aware configuration.

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.

    image

  • 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.

      image

    • Use :CocCommand with <tab> for command line completion.

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

      vim snippet
      1command! -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.

Extension trust and safety

coc.nvim extensions are Node.js code that can use Node.js and coc.nvim APIs. Install only packages and source repositories that you trust. Before installing or updating an extension, inspect its npm package or source repository and the version you plan to run.

To isolate startup or extension problems, set COC_NO_PLUGINS to 1 in your vimrc to disable extension loading:

vim snippet
1let $COC_NO_PLUGINS = '1'

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:

js snippet
1const { commands, workspace } = require('coc.nvim')
2 
3exports.activate = context => {
4 let { nvim } = workspace
5 context.subscriptions.push(commands.registerCommand('code.convertCodePoint', async () => {
6 let [pos, line] = await nvim.eval('[coc#util#cursor(), getline(".")]')
7 let curr = pos[1] == 0 ? '' : line.slice(pos[1], pos[1] + 1)
8 let code = curr.codePointAt(0)
9 let str = code.toString(16)
10 str = str.length == 4 ? str : '0'.repeat(4 - str.length) + str
11 let result = `${line.slice(0, pos[1])}${'\\u' + str}${line.slice(pos[1] + 1)}`
12 await nvim.call('setline', ['.', result])
13 }))
14}

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:

vim snippet
1: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:

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

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

sh snippet
1# install coc-json & coc-html and exit
2vim -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:

dosini snippet
1coc.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:

vim snippet
1:CocInstall [email protected]

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:

vim snippet
1Plug '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:

sh snippet
1vim -c 'CocUpdateSync|q'

Uninstall coc extension

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

vim snippet
1:CocUninstall coc-css

Manage extensions with CocList

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

vim snippet
1:CocList extensions

image

  • ? 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 </docs/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 </docs/debug-coc-nvim>.

Finding Extensions

Looking for extensions for your programming languages, linters, formatters, or tools? Start with the Extensions directory on this site. It is the recommended place to browse the current catalog, filter by language or category, review package metadata, and copy install commands. For extensions not listed there, search the coc.nvim packages tagged on npm for a broader community catalog.

You can also discover and manage extensions directly inside Vim:

Tip: Install coc-json to get schema-based completion and validation in coc-settings.json, then use :CocConfig to open the file. Other extensions can contribute settings schemas, but they do not provide the JSON editing support themselves.