Archived: now using https://github.com/stevearc/conform.nvim
conform.nvim runs formatters synchronously and uses stdin so that only a single file write is required.
Synchronous formatter runner for Neovim using in-place formatters. No stdin support.
- In-place formatting only, no stdin support.
- Simple configuration.
- Can run multiple formatters in sequence.
- Preserves scroll positions when editing the same buffer in multiple windows at different positions by using the
edit
command to reload the buffer.
Example using lazy.nvim:
{
"mgnsk/sync-format.nvim",
event = "BufEnter",
config = function()
require("formatter").setup({
typescript = { "prettier", "-w" },
lua = { "stylua", "--indent-type", "Spaces", "--indent-width", "4" },
fish = { "fish", "-c", [['fish_indent -w $argv[1]']] },
c = { "clang-format", "-i" },
proto = { "buf", "format", "-w" },
lua = { "stylua" },
go = {
{ "goimports", "-w" },
{ "gofumpt", "-w" },
},
rust = { "rustfmt" },
sh = { "shfmt", "-w" },
php = { "pint" },
sql = { "pg_format", "-i", "--type-case", "0" },
})
end,
}
The plugin provides a few commands:
AutoformatToggle
- Toggle autoformat globallyAutoformatEnable
- Enable autoformat globallyAutoformatDisable
- Disable autoformat globallyAutoformatToggleBuffer
- Toggle autoformat for bufferAutoformatEnableBuffer
- Enable autoformat for bufferAutoformatDisableBuffer
- Disable autoformat for buffer