47 lines
1.6 KiB
Lua
47 lines
1.6 KiB
Lua
-- =============================================================================
|
|
-- conform.lua — 自动格式化
|
|
-- =============================================================================
|
|
-- 【保留】你的完整 conform 配置。
|
|
-- 【修改】🔧 键位从 <leader>cf 改为 <leader>lf(与 LSP 格式化键统一);
|
|
-- ✅ 新增更多语言的 formatter。
|
|
|
|
return {
|
|
{
|
|
"stevearc/conform.nvim",
|
|
event = { "BufWritePre" },
|
|
cmd = { "ConformInfo" },
|
|
keys = {
|
|
-- 🔧 修改:<leader>cf → <leader>lf,与 keymaps.lua 中的 LSP 格式化键一致
|
|
{ "<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}" },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|