Skip to main content

Overview

conform.nvim provides fast, asynchronous code formatting with support for multiple formatters per filetype. All formatters must be installed globally. Configuration file: lua/plugins/formatter.lua:5

Installation

All formatters must be installed globally. See the installation documentation for platform-specific instructions.

Events and commands

event
string[]
default:"[\"BufWritePre\"]"
Loads the plugin before writing files (for format-on-save).
cmd
string[]
default:"[\"ConformInfo\"]"
Also loads when running :ConformInfo command.

Keymaps

<leader>fb
keymap
Format buffer - Manually formats the current buffer or visual selection
  • Modes: Normal and Visual
  • Async: true
  • Description: “[F]ormat [B]uffer”
  • Shows notification on successful format
function()
  require("conform").format({ async = true }, function(err, did_edit)
    if not err and did_edit then
      vim.notify("Code formatted", vim.log.levels.INFO, { title = "Conform" })
    end
  end)
end

Format-on-save

format_on_save.timeout_ms
number
default:"1000"
Maximum time (in milliseconds) to wait for formatting to complete. Aborts if exceeded.
format_on_save.lsp_format
string
default:"fallback"
Falls back to LSP formatting if no conform formatter is configured for the filetype.
Format-on-save runs synchronously with a 1-second timeout to ensure files are properly formatted before saving.

Formatter options

formatters['biome-check'].condition
function
The biome-check formatter only runs if a biome.json or biome.jsonc file exists in the project root.
condition = function(_, ctx)
  return vim.fs.find(
    { "biome.json", "biome.jsonc" },
    { path = ctx.filename, upward = true }
  )[1]
end
This prevents Biome from running in projects that don’t use it, improving performance.

Formatters by filetype

The configuration supports multiple formatters per filetype with fallback chains:
formatters_by_ft.lua
string[]
default:"[\"stylua\"]"
Uses stylua for Lua formatting.

Formatter chaining

The configuration uses two approaches for multiple formatters:
Some filetypes run multiple formatters in sequence:
go = { "goimports", "gofumpt" }
This runs goimports first, then gofumpt on the result.
Other filetypes try formatters until one succeeds:
javascript = { "biome-check", "prettier", stop_after_first = true }
This tries biome-check first. If it doesn’t apply (no biome.json), it falls back to prettier.
The stop_after_first = true option prevents running subsequent formatters if the first one succeeds.

Common commands

  • :ConformInfo - Show formatter status and configuration for current buffer
  • <leader>fb - Manually format buffer or selection
  • Format-on-save is automatic (can be disabled per-buffer if needed)

Configuration options

notify_on_error
boolean
default:"true"
Shows a notification if formatting fails.
The configuration sets Neovim’s formatexpr option:
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
This allows using gq motion for formatting with conform.nvim.
Python formatters (isort, black) are commented out in the configuration. Uncomment to enable Python formatting.

Build docs developers (and LLMs) love