Skip to main content
This configuration uses conform.nvim for code formatting. Format-on-save is enabled by default with a 1-second timeout.

Configuration

Formatters are configured in lua/plugins/formatter.lua:
-- From lua/plugins/formatter.lua:5
return {
  "stevearc/conform.nvim",
  event = { "BufWritePre" },
  cmd = { "ConformInfo" },
}

Format on save

Automatic formatting is enabled when you save a file:
-- From lua/plugins/formatter.lua:27
format_on_save = {
  timeout_ms = 1000,
  lsp_format = "fallback",
}
If formatting takes longer than 1 second, it will be aborted. If no formatter is configured, LSP formatting is used as fallback.

Manual formatting

You can also format manually:
-- From lua/plugins/formatter.lua:9
{
  "<leader>fb",
  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,
  mode = { "n", "v" },
  desc = "[F]ormat [B]uffer",
}
Press <leader>fb in normal or visual mode to format.

Formatters by language

Lua

-- From lua/plugins/formatter.lua:44
lua = { "stylua" }
Installation:
cargo install stylua
# or
brew install stylua

JavaScript/TypeScript

-- From lua/plugins/formatter.lua:54
javascript = { "biome-check", "prettier", stop_after_first = true },
javascriptreact = { "biome-check", "prettier", stop_after_first = true },
typescript = { "biome-check", "prettier", stop_after_first = true },
typescriptreact = { "biome-check", "prettier", stop_after_first = true },
Biome is tried first if biome.json or biome.jsonc exists in the project. Otherwise, Prettier is used.
biome-check behavior:
-- From lua/plugins/formatter.lua:33
formatters = {
  ["biome-check"] = {
    condition = function(_, ctx)
      return vim.fs.find(
        { "biome.json", "biome.jsonc" },
        { path = ctx.filename, upward = true }
      )[1]
    end,
  },
}
The biome-check formatter runs biome check --write which handles:
  • Code formatting
  • Import sorting
  • Safe lint fixes
Installation:
npm install -g @biomejs/biome prettier

Go

-- From lua/plugins/formatter.lua:71
go = { "goimports", "gofumpt" }
Both formatters run in sequence:
  1. goimports - Organize imports
  2. gofumpt - Stricter formatting than gofmt
Installation:
go install golang.org/x/tools/cmd/goimports@latest
go install mvdan.cc/gofumpt@latest

C/C++

-- From lua/plugins/formatter.lua:49
c = { "clang_format" },
cpp = { "clang_format" },
Installation:
brew install clang-format
# or install via LLVM

Shell scripts

-- From lua/plugins/formatter.lua:74
sh = { "shfmt" },
bash = { "shfmt" },
zsh = { "shfmt" },
Installation:
brew install shfmt
# or
go install mvdan.cc/sh/v3/cmd/shfmt@latest

Web and config files

-- From lua/plugins/formatter.lua:60
json = { "biome-check", "prettier", stop_after_first = true },
jsonc = { "biome-check", "prettier", stop_after_first = true },
css = { "biome-check", "prettier", stop_after_first = true },
scss = { "biome-check", "prettier", stop_after_first = true },
html = { "biome-check", "prettier", stop_after_first = true },
yaml = { "yamlfmt", stop_after_first = true },
yml = { "yamlfmt", stop_after_first = true },
toml = { "tombi", stop_after_first = true },
markdown = { "markdownlint-cli2", stop_after_first = true },
Installation:
# YAML
go install github.com/google/yamlfmt/cmd/yamlfmt@latest

# TOML
cargo install --locked tombi-cli

# Markdown
npm install -g markdownlint-cli2

Dockerfile

-- From lua/plugins/formatter.lua:79
dockerfile = { "dockerfmt" }
Installation:
brew install dockerfmt

Checking configuration

Use the :ConformInfo command to see:
  • Available formatters for current filetype
  • Formatter status (available/not available)
  • Formatter command and arguments

Format expression

Conform provides a custom formatexpr for use with the gq operator:
-- From lua/plugins/formatter.lua:23
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
This allows you to use gq to format text selections.

Error handling

-- From lua/plugins/formatter.lua:26
opts = {
  notify_on_error = true,
}
You’ll be notified if a formatter fails.

Complete formatter list

All formatters configured:
LanguageFormattersPriority
Luastylua
JavaScript/TypeScriptbiome-check, prettierbiome first
JSON/JSONCbiome-check, prettierbiome first
CSS/SCSSbiome-check, prettierbiome first
HTMLbiome-check, prettierbiome first
Gogoimports, gofumptboth run
C/C++clang_format
Shellshfmt
YAMLyamlfmt
TOMLtombi
Markdownmarkdownlint-cli2
Dockerfiledockerfmt

Installation guide

For complete installation instructions, see docs/install.md in the source repository.

Quick install

npm install -g prettier @biomejs/biome markdownlint-cli2

Next steps

Linting

Configure linters with nvim-lint

LSP setup

Configure language servers

Build docs developers (and LLMs) love