From 7b6af7d48637c2d8f030b3a16a5df2c67c3d5a0d Mon Sep 17 00:00:00 2001 From: Trey Bastian Date: Sat, 6 Jun 2026 09:05:46 +0100 Subject: created autocmd to toggle format on save (need this for work) --- lua/config/conform.lua | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lua/config/conform.lua b/lua/config/conform.lua index a6bb745..a65a9c4 100644 --- a/lua/config/conform.lua +++ b/lua/config/conform.lua @@ -27,8 +27,26 @@ require("conform").setup({ proto = { "buf", lsp_format = "fallback" }, odin = { "odinfmt" }, }, - format_on_save = { - timeout_ms = 1001, - lsp_format = "fallback", - }, + 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") -- cgit v1.2.3