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" },
}
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.
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.
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
-- From lua/plugins/formatter.lua:71
go = { "goimports", "gofumpt" }
Both formatters run in sequence:
goimports - Organize imports
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:
Checking configuration
Use the :ConformInfo command to see:
- Available formatters for current filetype
- Formatter status (available/not available)
- Formatter command and arguments
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.
All formatters configured:
| Language | Formatters | Priority |
|---|
| Lua | stylua | |
| JavaScript/TypeScript | biome-check, prettier | biome first |
| JSON/JSONC | biome-check, prettier | biome first |
| CSS/SCSS | biome-check, prettier | biome first |
| HTML | biome-check, prettier | biome first |
| Go | goimports, gofumpt | both run |
| C/C++ | clang_format | |
| Shell | shfmt | |
| YAML | yamlfmt | |
| TOML | tombi | |
| Markdown | markdownlint-cli2 | |
| Dockerfile | dockerfmt | |
Installation guide
For complete installation instructions, see docs/install.md in the source repository.
Quick install
npm install -g prettier @biomejs/biome markdownlint-cli2
brew install stylua shfmt clang-format dockerfmt
go install golang.org/x/tools/cmd/goimports@latest
go install mvdan.cc/gofumpt@latest
go install mvdan.cc/sh/v3/cmd/shfmt@latest
go install github.com/google/yamlfmt/cmd/yamlfmt@latest
cargo install stylua
cargo install --locked tombi-cli
Next steps
Linting
Configure linters with nvim-lint
LSP setup
Configure language servers