vim.pack.add({ "https://github.com/stevearc/conform.nvim", }) vim.keymap.set("n", "bf", function() require("conform").format({ async = true, lsp_format = "fallback", }) end) require("conform").setup({ formatters_by_ft = { lua = { "stylua" }, swift = { "swift" }, javascript = { "prettierd", "prettier" }, javascriptreact = { "prettierd", "prettier" }, typescript = { "prettierd", "prettier" }, typescriptreact = { "prettierd", "prettier" }, json = { "prettierd", "prettier" }, html = { "prettierd", "prettier" }, css = { "prettierd", "prettier" }, svelte = { "prettierd", "prettier" }, astro = { "prettierd", "prettier" }, rust = { "rustfmt", lsp_format = "fallbackk" }, go = { "goimports", "gofmt" }, proto = { "buf", lsp_format = "fallback" }, odin = { "odinfmt" }, }, format_on_save = function(bufnr) if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then return end return { timeout_ms = 1001, lsp_format = "fallback" } end, }) vim.api.nvim_create_user_command("FormatDisable", function(args) if args.bang then vim.b.disable_autoformat = true else vim.g.disable_autoformat = true end end, { desc = "Disable autoformat-on-save", bang = true }) vim.api.nvim_create_user_command("FormatEnable", function() vim.b.disable_autoformat = false vim.g.disable_autoformat = false end, { desc = "Re-enable autoformat-on-save" }) vim.keymap.set("n", "afd", "FormatDisable") vim.keymap.set("n", "afD", "FormatDisable!") vim.keymap.set("n", "afe", "FormatEnable")