Skip to main content
Back to Extensions Directory
coc.nvim fallback icon

coc-prettier

Neoclide

Prettier extension for coc.nvim

Installation CommandVim prompt
:CocInstall coc-prettier
GitHub owner
Neoclide
Version
v11.0.1
npm package
coc-prettier
Requirements
coc >= 0.0.82
License
MIT
Repository
GitHub
npm latest published 2025-06-11Registry checked 2026-08-23Registry summary

Published Package Summary

Prettier formatter for coc.nvim

Fork of prettier-vscode to work with coc.nvim

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

JavaScript · TypeScript · Flow · JSX · JSON
CSS · SCSS · Less
HTML · Vue · Angular HANDLEBARS · Ember · Glimmer
GraphQL · Markdown · YAML
Your favorite language?

Installation

Run vim command:

:CocInstall coc-prettier

Debug log

  • Add "prettier.enableDebugLogs": true to coc-settings.json opened by : CocConfig.
  • Checkout output by :CocCommand prettier.openOutput.

New feature of 11.0.0

  • Added configuration properties: prettier.singleAttributePerLine, prettier.jsxBracketSameLine and prettier.experimentalTernaries.

Prettier Resolution

This extension will use prettier from your project's local dependencies (recommended). When the prettier.resolveGlobalModules is set to true the extension can also attempt to resolve global modules. Should prettier not be installed locally with your project's dependencies or globally on the machine, the version of prettier that is bundled with the extension will be used.

To install prettier in your project and pin its version as recommended, run:

npm install prettier -D --save-exact

NOTE: You will be prompted to confirm that you want the extension to load a Prettier module. This is done to ensure that you are not loading a module or script that is not trusted.

Plugins

This extension supports Prettier plugins when you are using a locally or globally resolved version of prettier. If you have Prettier and a plugin registered in your package.json, this extension will attempt to register the language and provide automatic code formatting for the built-in and plugin languages.

Usage

Range format

Remap keys for range format in your init.vim or .vimrc

vmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

Then you can <leader>f for range format.

Format selection works on several languages depending on what Prettier itself supports. The following languages currently are supported:

javascript
javascriptreact
typescript
typescriptreact
json
graphql
handlebars

Format On Save.

Open settings file with:

:CocConfig

Add:

  "coc.preferences.formatOnSaveFiletypes": ["css", "markdown"],

to setup the languages which you want to format on save.

Note: if prettier extension have lower priority, and document have other registered document format provider, prettier will be ignored.

To disable coc-prettier for specific files, you can create .prettierignore file. Or use "prettier.disableLanguages" configuration, or "prettier.formatterPriority": -1 configuration to make it not override format provider from other coc.nvim extensions.

To check the format is done by prettier, check out the output message after format, which should contains Formatted by prettier.

Other useful commands:

  • :CocCommand prettier.formatFile: force prettier to format the current buffer, even if another format provider exists.
  • :noa w: save the current buffer without formatting.
  • :CocCommand prettier.createConfigFile: Create .prettierrc for current document.

Format Document (Forced)

If you would like to format a document that is configured to be ignored by Prettier either because it is in a .prettierignore file or part of a normally excluded location like node_modules, you can run the command Format Document (Forced) to force the document to be formatted. Forced mode will also ignore any config for requirePragma allowing you to format files without the pragma comment present.

Linter Integration

The recommended way of integrating with linters is to let Prettier do the formatting and configure the linter to not deal with formatting rules. You can find instructions on how to configure each linter on the Prettier docs site. You can then use each of the linting extensions as you normally would. For details refer to the Prettier documentation.

Error Messages

Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run npm install

When a package.json is present in your project and it contains prettier, plugins, or linter libraries this extension will attempt to load these modules from your node_module folder. If you see this error, it most likely means you need to run npm install or yarn install to install the packages in your package.json.

Your project is configured to use an outdated version of prettier that cannot be used by this extension. Upgrade to the latest version of prettier.

You have to upgrade to a newer version of prettier.

Contribute

Feel free to open issues or PRs!

Read the complete README
  • Prettier extension for coc.nvim
Activation Events
  • *
Developer Resources

Want to build, test, or contribute to coc.nvim extensions? Explore our official SDK and testing toolkits.

Open Developer Guide

Version History

Published with coc-prettier@11.0.1 as CHANGELOG.md.

Open source file

[9.3.2]

  • Fix issue with prettier v3.

[9.3.0]

  • Added additional debug logs.
  • Create minimal textEdit.

[9.2.0]

  • Removed support for legacy linter integration. See documentation on how to configure linters.
  • Removed prettier.disableSuccessMessage, no success message any more.
  • Removed support for Prettier versions older than 1.13.0.
  • No longer bundling linters with extension - to use install them in your package.json.
  • Use Prettier to determine if a file is ignored or not instead of custom logic.
  • Support for formatting of untitled files when the language is set by vim.
  • Set file path config on format to assist with parser resolution.
  • Less fallbacks - if you have local prettier installed it will always use that. Before if your local prettier didn't support things we would fall back to bundled prettier - this caused many errors and inconsistent behavior.
  • Enhanced logging.
  • Memoize package path lookup to improve perf of repeated calls to same file.
  • Shows error message when outdated versions of prettier are used.
  • Refreshes modules without restart for cases where prettier version or plugins are installed locally.
  • Registers .graphql files as graphql language in order to provide formatting.
  • Ignore files are only read from the workspace folder to behave the same as prettier.
  • Added configuration option prettier.prettierPath to override module resolution.
  • Added configuration option prettier.configPath to override configuration file resolution.
  • Add command Prettier: Create Configuration File to create a basic .prettierrc file
  • Sets resolveConfig: true to allow parser overrides on Prettier 1.19+. #1067
  • Added setting prettier.useEditorConfig (defaults to true) to allow disabling resolving .editorconfig for Prettier config
  • Added pattern filter to formatter registrations to avoid registering incorrectly on multi-workspace projects
  • Added support for global module resolution, due to performance issues, global module resolution is now off by default. Enable by setting prettier.resolveGlobalModules to true
  • Added setting packageManager to determine which package manager to use for global module resolution
  • Show error when prettier configuration file is invalid
  • Change default configuration for trailingComma to es5 to match Prettier 2.0
  • Change default configuration for arrowParens to always to match Prettier 2.0
  • Change default configuration for endOfLine to lf to match Prettier 2.0
  • Added configuration option withNodeModules to enable processing of files in the node_modules folder
  • Update loading implicit Prettier dep from node_modules to only occur if explicit package.json dep is not found in a parent directory
  • Support for additional configuration file extensions (toml, cls).
  • Added support for custom document selectors to provide formatting on custom languages/extensions.
  • Added Embedded Language Formatting option.
  • Added enable setting.
  • Automatically detect package manager
  • Prompt to allow Prettier module to load
  • Added debug mode for logging
  • Handlebars support (@lifeart)

[1.1.13]

  • Just bumping minor version to accommodate yarn upgrade to fix issue reported by yarn audit.

[1.1.0]

  • Prettier 1.16
  • prettier-tslint 0.4.2
  • Validate the "prettier" key in package.json using the prettier settings schema
  • Prettier 1.15
  • New options: jsxSingleQuote, htmlWhitespaceSensitivity and endOfLine (More info in readme).