Lightweight yet powerful formatter plugin for Neovim
5,336
stars
628
commits
Lua
primary language
Aug 11, 2026
updated
Lightweight yet powerful formatter plugin for Neovim
vim.lsp.buf.format().conform.nvim supports all the usual plugin managers
{
'stevearc/conform.nvim',
opts = {},
}
For a more thorough configuration involving lazy-loading, see Lazy loading with lazy.nvim.
require("packer").startup(function()
use({
"stevearc/conform.nvim",
config = function()
require("conform").setup()
end,
})
end)
require("paq")({
{ "stevearc/conform.nvim" },
})
Plug 'stevearc/conform.nvim'
call dein#add('stevearc/conform.nvim')
git clone --depth=1 https://github.com/stevearc/conform.nvim.git ~/.vim/bundle/
git clone --depth=1 https://github.com/stevearc/conform.nvim.git \
"${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/conform/start/conform.nvim
At a minimum, you will need to set up some formatters by filetype
require("conform").setup({
formatters_by_ft = {
lua = { "stylua" },
-- Conform will run multiple formatters sequentially
python = { "isort", "black" },
-- You can customize some of the format options for the filetype (:help conform.format)
rust = { "rustfmt", lsp_format = "fallback" },
-- Conform will run the first available formatter
javascript = { "prettierd", "prettier", stop_after_first = true },
},
})
Then you can use conform.format() just like you would vim.lsp.buf.format(). For example, to format on save:
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*",
callback = function(args)
require("conform").format({ bufnr = args.buf })
end,
})
As a shortcut, conform will optionally set up this format-on-save autocmd for you
require("conform").setup({
format_on_save = {
-- These options will be passed to conform.format()
timeout_ms = 500,
lsp_format = "fallback",
},
})
See conform.format() for more details about the parameters.
Conform also provides a formatexpr, same as the LSP client:
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
To view configured and available formatters, as well as to see the log file, run :ConformInfo
You can view this list in vim with :help conform-formatters
biome-check or biome-organize-imports for other options.biome or biome-organize-imports for other options.biome or biome-check for other options.cue fmt command.rsx! snippets in Rust files.opa fmt command.bash support.cat -s.swift formatter instead.swift code on macOS or Linux.terraform configuration files to a canonical format and style.You can override/add to the default values of formatters
require("conform").setup({
formatters = {
yamlfix = {
-- Change where to find the command
command = "local/path/yamlfix",
-- Adds environment args to the yamlfix formatter
env = {
YAMLFIX_SEQUENCE_STYLE = "block_style",
},
},
},
})
-- These can also be set directly
require("conform").formatters.yamlfix = {
env = {
YAMLFIX_SEQUENCE_STYLE = "block_style",
},
}
-- This can also be a function that returns the config,
-- which can be useful if you're doing lazy loading
require("conform").formatters.yamlfix = function(bufnr)
return {
command = require("conform.util").find_executable({
"local/path/yamlfix",
}, "yamlfix"),
}
end
In addition to being able to override any of the original properties on the formatter, there is another property for easily adding additional arguments to the format command
require("conform").formatters.shfmt = {
append_args = { "-i", "2" },
-- The base args are { "-filename", "$FILENAME" } so the final args will be
-- { "-filename", "$FILENAME", "-i", "2" }
}
-- append_args can be a function, just like args
require("conform").formatters.shfmt = {
append_args = function(self, ctx)
return { "-i", "2" }
end,
}
If you want to overwrite the entire formatter definition and not merge with the default values, pass inherit = false. This is also the default behavior if there is no built-in formatter with the given name, which can be used to add your own custom formatters.
require("conform").formatters.shfmt = {
inherit = false,
command = "shfmt",
args = { "-filename", "$FILENAME", "-i", "2" },
}
You can also specify which formatter to inherit from. This can be useful if you want to define multiple variants of a single formatter with slightly different options.
require("conform").formatters.deno_fmt_markdown = {
inherit = "deno_fmt",
append_args = { "--indent-width", "4" },
}
The following magic strings are available in args and range_args. They will be dynamically replaced at runtime with the relevant value.
$FILENAME - absolute path to the file$DIRNAME - absolute path to the directory that contains the file$RELATIVE_FILEPATH - relative path to the file$EXTENSION - the file extension, e.g. .pyA complete list of all configuration options
require("conform").setup({
-- Map of filetype to formatters
formatters_by_ft = {
lua = { "stylua" },
-- Conform will run multiple formatters sequentially
go = { "goimports", "gofmt" },
-- You can also customize some of the format options for the filetype
rust = { "rustfmt", lsp_format = "fallback" },
-- You can use a function here to determine the formatters dynamically
python = function(bufnr)
if require("conform").get_formatter_info("ruff_format", bufnr).available then
return { "ruff_format" }
else
return { "isort", "black" }
end
end,
-- Use the "*" filetype to run formatters on all filetypes.
["*"] = { "codespell" },
-- Use the "_" filetype to run formatters on filetypes that don't
-- have other formatters configured.
["_"] = { "trim_whitespace" },
},
-- Set this to change the default values when calling conform.format()
-- This will also affect the default values for format_on_save/format_after_save
default_format_opts = {
lsp_format = "fallback",
},
-- If this is set, Conform will run the formatter on save.
-- It will pass the table to conform.format().
-- This can also be a function that returns the table.
format_on_save = {
-- I recommend these options. See :help conform.format for details.
lsp_format = "fallback",
timeout_ms = 500,
},
-- If this is set, Conform will run the formatter asynchronously after save.
-- It will pass the table to conform.format().
-- This can also be a function that returns the table.
format_after_save = {
lsp_format = "fallback",
},
-- Set the log level. Use `:ConformInfo` to see the location of the log file.
log_level = vim.log.levels.ERROR,
-- Conform will notify you when a formatter errors
notify_on_error = true,
-- Conform will notify you when no formatters are available for the buffer
notify_no_formatters = true,
-- Custom formatters and overrides for built-in formatters
formatters = {
my_formatter = {
-- This can be a string or a function that returns a string.
-- When defining a new formatter, this is the only field that is required
command = "my_cmd",
-- A list of strings, or a function that returns a list of strings
-- Return a single string instead of a list to run the command in a shell
args = { "--stdin-from-filename", "$FILENAME" },
-- If the formatter supports range formatting, create the range arguments here
range_args = function(self, ctx)
return { "--line-start", ctx.range.start[1], "--line-end", ctx.range["end"][1] }
end,
-- Send file contents to stdin, read new contents from stdout (default true)
-- When false, will create a temp file (will appear in "$FILENAME" args). The temp
-- file is assumed to be modified in-place by the format command.
stdin = true,
-- A function that calculates the directory to run the command in
cwd = require("conform.util").root_file({ ".editorconfig", "package.json" }),
-- When cwd is not found, don't run the formatter (default false)
require_cwd = true,
-- When stdin=false, use this template to generate the temporary file that gets formatted
tmpfile_format = ".conform.$RANDOM.$FILENAME",
-- When returns false, the formatter will not be used
condition = function(self, ctx)
return vim.fs.basename(ctx.filename) ~= "README.md"
end,
-- Exit codes that indicate success (default { 0 })
exit_codes = { 0, 1 },
-- Environment variables. This can also be a function that returns a table.
env = {
VAR = "value",
},
-- Set to false to disable merging the config with the base definition.
-- Can also be set to the name of the formatter to merge with (e.g. inherit = "black")
inherit = true,
-- When inherit = true, add these additional arguments to the beginning of the command.
-- This can also be a function, like args
prepend_args = { "--use-tabs" },
-- When inherit = true, add these additional arguments to the end of the command.
-- This can also be a function, like args
append_args = { "--trailing-comma" },
},
-- These can also be a function that returns the formatter
other_formatter = function(bufnr)
return {
command = "my_cmd",
}
end,
},
})
-- You can set formatters_by_ft and formatters directly
require("conform").formatters_by_ft.lua = { "stylua" }
require("conform").formatters.my_formatter = {
command = "my_cmd",
}
setup(opts)
| Param | Type | Desc |
|---|---|---|
| opts | nil|conform.setupOpts | |
| >formatters_by_ft | nil|table<string, conform.FiletypeFormatter> | Map of filetype to formatters |
| >format_on_save | nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts | If this is set, Conform will run the formatter on save. It will pass the table to conform.format(). This can also be a function that returns the table. |
| >default_format_opts | nil|conform.DefaultFormatOpts | The default options to use when calling conform.format() |
| >>timeout_ms | nil|integer | Time in milliseconds to block for formatting. Defaults to 1000. No effect if async = true. |
| >>lsp_format | nil|conform.LspFormatOpts | Configure if and when LSP should be used for formatting. Defaults to "never". |
"never" | never use the LSP for formatting (default) | |
"fallback" | LSP formatting is used when no other formatters are available | |
"prefer" | use only LSP formatting when available | |
"first" | LSP formatting is used when available and then other formatters | |
"last" | other formatters are used then LSP formatting when available | |
| >>quiet | nil|boolean | Don't show any notifications for warnings or failures. Defaults to false. |
| >>stop_after_first | nil|boolean | Only run the first available formatter in the list. Defaults to false. |
| >format_after_save | nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts | , nil |
| >log_level | nil|integer | Set the log level (e.g. vim.log.levels.DEBUG). Use :ConformInfo to see the location of the log file. |
| >notify_on_error | nil|boolean | Conform will notify you when a formatter errors (default true). |
| >notify_no_formatters | nil|boolean | Conform will notify you when no formatters are available for the buffer (default true). |
| >formatters | nil|table<string, conform.FormatterConfigOverride|fun(bufnr: integer): nil|conform.FormatterConfigOverride> | Custom formatters and overrides for built-in formatters. |
format(opts, callback): boolean
Format a buffer
| Param | Type | Desc |
|---|---|---|
| opts | nil|conform.FormatOpts | |
| >timeout_ms | nil|integer | Time in milliseconds to block for formatting. Defaults to 1000. No effect if async = true. |
| >bufnr | nil|integer | Format this buffer (default 0) |
| >async | nil|boolean | If true the method won't block. Defaults to false. If the buffer is modified before the formatter completes, the formatting will be discarded. |
| >dry_run | nil|boolean | If true don't apply formatting changes to the buffer |
| >undojoin | nil|boolean | Use undojoin to merge formatting changes with previous edit (default false) |
| >formatters | nil|string[] | List of formatters to run. Defaults to all formatters for the buffer filetype. |
| >lsp_format | nil|conform.LspFormatOpts | Configure if and when LSP should be used for formatting. Defaults to "never". |
"never" | never use the LSP for formatting (default) | |
"fallback" | LSP formatting is used when no other formatters are available | |
"prefer" | use only LSP formatting when available | |
"first" | LSP formatting is used when available and then other formatters | |
"last" | other formatters are used then LSP formatting when available | |
| >stop_after_first | nil|boolean | Only run the first available formatter in the list. Defaults to false. |
| >quiet | nil|boolean | Don't show any notifications for warnings or failures. Defaults to false. |
| >range | nil|conform.Range | Range to format. Table must contain start and end keys with {row, col} tuples using (1,0) indexing. Defaults to current selection in visual mode |
| >>start | integer[] | |
| >>end | integer[] | |
| >id | nil|integer | Passed to vim.lsp.buf.format when using LSP formatting |
| >name | nil|string | Passed to vim.lsp.buf.format when using LSP formatting |
| >filter | nil|fun(client: table): boolean | Passed to vim.lsp.buf.format when using LSP formatting |
| >formatting_options | nil|table | Passed to vim.lsp.buf.format when using LSP formatting |
| callback | nil|fun(err: nil|string, did_edit: nil|boolean) | Called once formatting has completed |
Returns:
| Type | Desc |
|---|---|
| boolean | True if any formatters were attempted |
Examples:
-- Synchronously format the current buffer
conform.format({ lsp_format = "fallback" })
-- Asynchronously format the current buffer; will not block the UI
conform.format({ async = true }, function(err, did_edit)
-- called after formatting
end)
-- Format the current buffer with a specific formatter
conform.format({ formatters = { "ruff_fix" } })
list_formatters(bufnr): conform.FormatterInfo[]
Retrieve the available formatters for a buffer
| Param | Type | Desc |
|---|---|---|
| bufnr | nil|integer |
list_formatters_to_run(bufnr): conform.FormatterInfo[], boolean
Get the exact formatters that will be run for a buffer.
| Param | Type | Desc |
|---|---|---|
| bufnr | nil|integer |
Returns:
| Type | Desc |
|---|---|
| conform.FormatterInfo[] | |
| boolean | lsp Will use LSP formatter |
Note:
This accounts for stop_after_first, lsp fallback logic, etc.
list_all_formatters(): conform.FormatterInfo[]
List information about all filetype-configured formatters
get_formatter_info(formatter, bufnr): conform.FormatterInfo
Get information about a formatter (including availability)
| Param | Type | Desc |
|---|---|---|
| formatter | string | The name of the formatter |
| bufnr | nil|integer |
Q: Instead of passing lsp_format = "...", could you just define a lsp formatter?
A: No. #61
Q: Is it possible to define a custom formatter that runs a lua function?
A: Yes, but with some very strict constraints. #653
Q: Can I run a command like :EslintFixAll or a LSP code action as a formatter?
A: No. #502, #466, #222
Thanks to
(top 30 of 241)
Lua
96.0%
Python
2.9%
Lightweight yet powerful formatter plugin for Neovim
5,336
stars
628
commits
Lua
primary language
Aug 11, 2026
updated
Lightweight yet powerful formatter plugin for Neovim
vim.lsp.buf.format().conform.nvim supports all the usual plugin managers
{
'stevearc/conform.nvim',
opts = {},
}
For a more thorough configuration involving lazy-loading, see Lazy loading with lazy.nvim.
require("packer").startup(function()
use({
"stevearc/conform.nvim",
config = function()
require("conform").setup()
end,
})
end)
require("paq")({
{ "stevearc/conform.nvim" },
})
Plug 'stevearc/conform.nvim'
call dein#add('stevearc/conform.nvim')
git clone --depth=1 https://github.com/stevearc/conform.nvim.git ~/.vim/bundle/
git clone --depth=1 https://github.com/stevearc/conform.nvim.git \
"${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/conform/start/conform.nvim
At a minimum, you will need to set up some formatters by filetype
require("conform").setup({
formatters_by_ft = {
lua = { "stylua" },
-- Conform will run multiple formatters sequentially
python = { "isort", "black" },
-- You can customize some of the format options for the filetype (:help conform.format)
rust = { "rustfmt", lsp_format = "fallback" },
-- Conform will run the first available formatter
javascript = { "prettierd", "prettier", stop_after_first = true },
},
})
Then you can use conform.format() just like you would vim.lsp.buf.format(). For example, to format on save:
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*",
callback = function(args)
require("conform").format({ bufnr = args.buf })
end,
})
As a shortcut, conform will optionally set up this format-on-save autocmd for you
require("conform").setup({
format_on_save = {
-- These options will be passed to conform.format()
timeout_ms = 500,
lsp_format = "fallback",
},
})
See conform.format() for more details about the parameters.
Conform also provides a formatexpr, same as the LSP client:
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
To view configured and available formatters, as well as to see the log file, run :ConformInfo
You can view this list in vim with :help conform-formatters
biome-check or biome-organize-imports for other options.biome or biome-organize-imports for other options.biome or biome-check for other options.cue fmt command.rsx! snippets in Rust files.opa fmt command.bash support.cat -s.swift formatter instead.swift code on macOS or Linux.terraform configuration files to a canonical format and style.You can override/add to the default values of formatters
require("conform").setup({
formatters = {
yamlfix = {
-- Change where to find the command
command = "local/path/yamlfix",
-- Adds environment args to the yamlfix formatter
env = {
YAMLFIX_SEQUENCE_STYLE = "block_style",
},
},
},
})
-- These can also be set directly
require("conform").formatters.yamlfix = {
env = {
YAMLFIX_SEQUENCE_STYLE = "block_style",
},
}
-- This can also be a function that returns the config,
-- which can be useful if you're doing lazy loading
require("conform").formatters.yamlfix = function(bufnr)
return {
command = require("conform.util").find_executable({
"local/path/yamlfix",
}, "yamlfix"),
}
end
In addition to being able to override any of the original properties on the formatter, there is another property for easily adding additional arguments to the format command
require("conform").formatters.shfmt = {
append_args = { "-i", "2" },
-- The base args are { "-filename", "$FILENAME" } so the final args will be
-- { "-filename", "$FILENAME", "-i", "2" }
}
-- append_args can be a function, just like args
require("conform").formatters.shfmt = {
append_args = function(self, ctx)
return { "-i", "2" }
end,
}
If you want to overwrite the entire formatter definition and not merge with the default values, pass inherit = false. This is also the default behavior if there is no built-in formatter with the given name, which can be used to add your own custom formatters.
require("conform").formatters.shfmt = {
inherit = false,
command = "shfmt",
args = { "-filename", "$FILENAME", "-i", "2" },
}
You can also specify which formatter to inherit from. This can be useful if you want to define multiple variants of a single formatter with slightly different options.
require("conform").formatters.deno_fmt_markdown = {
inherit = "deno_fmt",
append_args = { "--indent-width", "4" },
}
The following magic strings are available in args and range_args. They will be dynamically replaced at runtime with the relevant value.
$FILENAME - absolute path to the file$DIRNAME - absolute path to the directory that contains the file$RELATIVE_FILEPATH - relative path to the file$EXTENSION - the file extension, e.g. .pyA complete list of all configuration options
require("conform").setup({
-- Map of filetype to formatters
formatters_by_ft = {
lua = { "stylua" },
-- Conform will run multiple formatters sequentially
go = { "goimports", "gofmt" },
-- You can also customize some of the format options for the filetype
rust = { "rustfmt", lsp_format = "fallback" },
-- You can use a function here to determine the formatters dynamically
python = function(bufnr)
if require("conform").get_formatter_info("ruff_format", bufnr).available then
return { "ruff_format" }
else
return { "isort", "black" }
end
end,
-- Use the "*" filetype to run formatters on all filetypes.
["*"] = { "codespell" },
-- Use the "_" filetype to run formatters on filetypes that don't
-- have other formatters configured.
["_"] = { "trim_whitespace" },
},
-- Set this to change the default values when calling conform.format()
-- This will also affect the default values for format_on_save/format_after_save
default_format_opts = {
lsp_format = "fallback",
},
-- If this is set, Conform will run the formatter on save.
-- It will pass the table to conform.format().
-- This can also be a function that returns the table.
format_on_save = {
-- I recommend these options. See :help conform.format for details.
lsp_format = "fallback",
timeout_ms = 500,
},
-- If this is set, Conform will run the formatter asynchronously after save.
-- It will pass the table to conform.format().
-- This can also be a function that returns the table.
format_after_save = {
lsp_format = "fallback",
},
-- Set the log level. Use `:ConformInfo` to see the location of the log file.
log_level = vim.log.levels.ERROR,
-- Conform will notify you when a formatter errors
notify_on_error = true,
-- Conform will notify you when no formatters are available for the buffer
notify_no_formatters = true,
-- Custom formatters and overrides for built-in formatters
formatters = {
my_formatter = {
-- This can be a string or a function that returns a string.
-- When defining a new formatter, this is the only field that is required
command = "my_cmd",
-- A list of strings, or a function that returns a list of strings
-- Return a single string instead of a list to run the command in a shell
args = { "--stdin-from-filename", "$FILENAME" },
-- If the formatter supports range formatting, create the range arguments here
range_args = function(self, ctx)
return { "--line-start", ctx.range.start[1], "--line-end", ctx.range["end"][1] }
end,
-- Send file contents to stdin, read new contents from stdout (default true)
-- When false, will create a temp file (will appear in "$FILENAME" args). The temp
-- file is assumed to be modified in-place by the format command.
stdin = true,
-- A function that calculates the directory to run the command in
cwd = require("conform.util").root_file({ ".editorconfig", "package.json" }),
-- When cwd is not found, don't run the formatter (default false)
require_cwd = true,
-- When stdin=false, use this template to generate the temporary file that gets formatted
tmpfile_format = ".conform.$RANDOM.$FILENAME",
-- When returns false, the formatter will not be used
condition = function(self, ctx)
return vim.fs.basename(ctx.filename) ~= "README.md"
end,
-- Exit codes that indicate success (default { 0 })
exit_codes = { 0, 1 },
-- Environment variables. This can also be a function that returns a table.
env = {
VAR = "value",
},
-- Set to false to disable merging the config with the base definition.
-- Can also be set to the name of the formatter to merge with (e.g. inherit = "black")
inherit = true,
-- When inherit = true, add these additional arguments to the beginning of the command.
-- This can also be a function, like args
prepend_args = { "--use-tabs" },
-- When inherit = true, add these additional arguments to the end of the command.
-- This can also be a function, like args
append_args = { "--trailing-comma" },
},
-- These can also be a function that returns the formatter
other_formatter = function(bufnr)
return {
command = "my_cmd",
}
end,
},
})
-- You can set formatters_by_ft and formatters directly
require("conform").formatters_by_ft.lua = { "stylua" }
require("conform").formatters.my_formatter = {
command = "my_cmd",
}
setup(opts)
| Param | Type | Desc |
|---|---|---|
| opts | nil|conform.setupOpts | |
| >formatters_by_ft | nil|table<string, conform.FiletypeFormatter> | Map of filetype to formatters |
| >format_on_save | nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts | If this is set, Conform will run the formatter on save. It will pass the table to conform.format(). This can also be a function that returns the table. |
| >default_format_opts | nil|conform.DefaultFormatOpts | The default options to use when calling conform.format() |
| >>timeout_ms | nil|integer | Time in milliseconds to block for formatting. Defaults to 1000. No effect if async = true. |
| >>lsp_format | nil|conform.LspFormatOpts | Configure if and when LSP should be used for formatting. Defaults to "never". |
"never" | never use the LSP for formatting (default) | |
"fallback" | LSP formatting is used when no other formatters are available | |
"prefer" | use only LSP formatting when available | |
"first" | LSP formatting is used when available and then other formatters | |
"last" | other formatters are used then LSP formatting when available | |
| >>quiet | nil|boolean | Don't show any notifications for warnings or failures. Defaults to false. |
| >>stop_after_first | nil|boolean | Only run the first available formatter in the list. Defaults to false. |
| >format_after_save | nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts | , nil |
| >log_level | nil|integer | Set the log level (e.g. vim.log.levels.DEBUG). Use :ConformInfo to see the location of the log file. |
| >notify_on_error | nil|boolean | Conform will notify you when a formatter errors (default true). |
| >notify_no_formatters | nil|boolean | Conform will notify you when no formatters are available for the buffer (default true). |
| >formatters | nil|table<string, conform.FormatterConfigOverride|fun(bufnr: integer): nil|conform.FormatterConfigOverride> | Custom formatters and overrides for built-in formatters. |
format(opts, callback): boolean
Format a buffer
| Param | Type | Desc |
|---|---|---|
| opts | nil|conform.FormatOpts | |
| >timeout_ms | nil|integer | Time in milliseconds to block for formatting. Defaults to 1000. No effect if async = true. |
| >bufnr | nil|integer | Format this buffer (default 0) |
| >async | nil|boolean | If true the method won't block. Defaults to false. If the buffer is modified before the formatter completes, the formatting will be discarded. |
| >dry_run | nil|boolean | If true don't apply formatting changes to the buffer |
| >undojoin | nil|boolean | Use undojoin to merge formatting changes with previous edit (default false) |
| >formatters | nil|string[] | List of formatters to run. Defaults to all formatters for the buffer filetype. |
| >lsp_format | nil|conform.LspFormatOpts | Configure if and when LSP should be used for formatting. Defaults to "never". |
"never" | never use the LSP for formatting (default) | |
"fallback" | LSP formatting is used when no other formatters are available | |
"prefer" | use only LSP formatting when available | |
"first" | LSP formatting is used when available and then other formatters | |
"last" | other formatters are used then LSP formatting when available | |
| >stop_after_first | nil|boolean | Only run the first available formatter in the list. Defaults to false. |
| >quiet | nil|boolean | Don't show any notifications for warnings or failures. Defaults to false. |
| >range | nil|conform.Range | Range to format. Table must contain start and end keys with {row, col} tuples using (1,0) indexing. Defaults to current selection in visual mode |
| >>start | integer[] | |
| >>end | integer[] | |
| >id | nil|integer | Passed to vim.lsp.buf.format when using LSP formatting |
| >name | nil|string | Passed to vim.lsp.buf.format when using LSP formatting |
| >filter | nil|fun(client: table): boolean | Passed to vim.lsp.buf.format when using LSP formatting |
| >formatting_options | nil|table | Passed to vim.lsp.buf.format when using LSP formatting |
| callback | nil|fun(err: nil|string, did_edit: nil|boolean) | Called once formatting has completed |
Returns:
| Type | Desc |
|---|---|
| boolean | True if any formatters were attempted |
Examples:
-- Synchronously format the current buffer
conform.format({ lsp_format = "fallback" })
-- Asynchronously format the current buffer; will not block the UI
conform.format({ async = true }, function(err, did_edit)
-- called after formatting
end)
-- Format the current buffer with a specific formatter
conform.format({ formatters = { "ruff_fix" } })
list_formatters(bufnr): conform.FormatterInfo[]
Retrieve the available formatters for a buffer
| Param | Type | Desc |
|---|---|---|
| bufnr | nil|integer |
list_formatters_to_run(bufnr): conform.FormatterInfo[], boolean
Get the exact formatters that will be run for a buffer.
| Param | Type | Desc |
|---|---|---|
| bufnr | nil|integer |
Returns:
| Type | Desc |
|---|---|
| conform.FormatterInfo[] | |
| boolean | lsp Will use LSP formatter |
Note:
This accounts for stop_after_first, lsp fallback logic, etc.
list_all_formatters(): conform.FormatterInfo[]
List information about all filetype-configured formatters
get_formatter_info(formatter, bufnr): conform.FormatterInfo
Get information about a formatter (including availability)
| Param | Type | Desc |
|---|---|---|
| formatter | string | The name of the formatter |
| bufnr | nil|integer |
Q: Instead of passing lsp_format = "...", could you just define a lsp formatter?
A: No. #61
Q: Is it possible to define a custom formatter that runs a lua function?
A: Yes, but with some very strict constraints. #653
Q: Can I run a command like :EslintFixAll or a LSP code action as a formatter?
A: No. #502, #466, #222
Thanks to
(top 30 of 241)
Lua
96.0%
Python
2.9%