1 -- Lightweight yet powerful formatter plugin for Neovim
2 -- https://github.com/stevearc/conform.nvim
3 vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
6 event = { "BufWritePre" },
7 cmd = { "ConformInfo" },
9 require("conform").setup({
10 -- Map of filetype to formatters
12 elm = { "elm-format" },
14 -- Conform will run multiple formatters sequentially
15 go = { "goimports", "gofmt" },
16 haskell = { "fourmolu" },
18 -- You can also customize some of the format options for the filetype
19 rust = { "rustfmt", lsp_format = "fallback" },
20 -- You can use a function here to determine the formatters dynamically
21 python = function(bufnr)
22 if require("conform").get_formatter_info("ruff_format", bufnr).available then
23 return { "ruff_format" }
25 return { "isort", "black" }
29 -- Use the "*" filetype to run formatters on all filetypes.
30 ["*"] = { "codespell" },
31 -- Use the "_" filetype to run formatters on filetypes that don't
32 -- have other formatters configured.
33 ["_"] = { "trim_whitespace" },
35 -- Set this to change the default values when calling conform.format()
36 -- This will also affect the default values for format_on_save/format_after_save
37 default_format_opts = {
38 lsp_format = "fallback",
40 -- If this is set, Conform will run the formatter on save.
41 -- It will pass the table to conform.format().
42 -- This can also be a function that returns the table.
43 format_after_save = function()
44 if not vim.g.formatsave or vim.b.disableFormatSave then
47 return { lsp_format = "fallback" }
50 format_on_save = function()
51 if not vim.g.formatsave or vim.b.disableFormatSave then
54 return { lsp_format = "fallback", timeout_ms = 500 }
57 -- Set the log level. Use `:ConformInfo` to see the location of the log file.
58 log_level = vim.log.levels.ERROR,
59 -- Conform will notify you when a formatter errors
60 notify_on_error = true,
61 -- Conform will notify you when no formatters are available for the buffer
62 notify_no_formatters = true,
63 -- Custom formatters and overrides for built-in formatters