Files
dotfiles/nvim/lua/plugins/conform.lua
T
2026-07-19 20:39:54 +08:00

42 lines
1.3 KiB
Lua

-- =============================================================================
-- conform.lua — 自动格式化
-- =============================================================================
return {
{
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
keys = {
{ "<leader>lf", function() require("conform").format({ async = true, lsp_fallback = true }) end, desc = "格式化" },
},
opts = {
format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
formatters_by_ft = {
rust = { "rustfmt" },
lua = { "stylua" },
c = { "clang-format" },
cpp = { "clang-format" },
python = { "black", "isort" },
javascript = { "prettier" },
typescript = { "prettier" },
json = { "prettier" },
yaml = { "prettier" },
markdown = { "prettier" },
html = { "prettier" },
css = { "prettier" },
go = { "gofmt", "goimports" },
sh = { "shfmt" },
},
formatters = {
["clang-format"] = {
args = { "--style={BasedOnStyle: LLVM, IndentWidth: 4, TabWidth: 4, UseTab: Never, ColumnLimit: 0}" },
},
},
},
},
}