-- 格式化插件
{
"stevearc/conform.nvim",
event = { "BufWritePre" }, -- 在保存文件前触发
cmd = { "ConformInfo" },
config = function()
require("conform").setup({
-- 定义不同文件类型的格式化工具
formatters_by_ft = {
c = { "clang-format" },
cpp = { "clang-format" },
lua = { "stylua" },
-- 在这里可以为其他语言添加格式化工具
},
-- 设置保存时自动格式化
format_on_save = {
timeout_ms = 500,
lsp_fallback = true,
},
})
end,
},因为我下面使用了 format_on_save 所以必须得 :w 才能格式化。