59 lines
1.5 KiB
Lua
59 lines
1.5 KiB
Lua
return {
|
|
"stevearc/conform.nvim",
|
|
event = { "BufWritePre" },
|
|
cmd = { "ConformInfo" },
|
|
keys = {
|
|
{
|
|
-- Customize or remove this keymap to your liking
|
|
"<leader>F",
|
|
function()
|
|
require("conform").format({ async = true, lsp_fallback = true })
|
|
end,
|
|
mode = "",
|
|
desc = "Format buffer",
|
|
},
|
|
},
|
|
-- Everything in opts will be passed to setup()
|
|
opts = {
|
|
-- Define your formatters
|
|
formatters_by_ft = {
|
|
lua = { "stylua" },
|
|
sh = { "shfmt" },
|
|
python = { "ruff_organize_imports_only" },
|
|
go = { "goimports", "gofmt" },
|
|
html = { "prettierd", "prettier", stop_after_first = true },
|
|
css = { "prettierd", "prettier", stop_after_first = true },
|
|
javascript = { "prettierd", "prettier", stop_after_first = true },
|
|
typescript = { "prettierd", "prettier", stop_after_first = true },
|
|
json = { "prettierd", "prettier", stop_after_first = true },
|
|
jsonc = { "prettierd", "prettier", stop_after_first = true },
|
|
markdown = { "prettierd", "prettier", stop_after_first = true },
|
|
},
|
|
-- Custom formatters
|
|
formatters = {
|
|
prettierd = {
|
|
args = { "--tab-width", "2" },
|
|
},
|
|
ruff_organize_imports_only = {
|
|
command = "ruff",
|
|
args = {
|
|
"check",
|
|
"--select",
|
|
"I001",
|
|
"--fix",
|
|
"--stdin-filename",
|
|
"$FILENAME",
|
|
"-",
|
|
},
|
|
stdin = true,
|
|
},
|
|
},
|
|
-- Set up format-on-save
|
|
format_on_save = { timeout_ms = 500, lsp_fallback = true },
|
|
},
|
|
init = function()
|
|
-- If you want the formatexpr, here is the place to set it
|
|
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
|
|
end,
|
|
}
|