diff options
| author | Trey Bastian <hello@treybastian.com> | 2026-06-06 09:05:46 +0100 |
|---|---|---|
| committer | Trey Bastian <hello@treybastian.com> | 2026-06-06 09:05:46 +0100 |
| commit | 7b6af7d48637c2d8f030b3a16a5df2c67c3d5a0d (patch) | |
| tree | 0c66ae00796e02f760858b62bedbdf73ba48fcf9 | |
| parent | a8b140ddff1b6d504f42f8899945e47cd9333374 (diff) | |
created autocmd to toggle format on save (need this for work)
| -rw-r--r-- | lua/config/conform.lua | 26 |
1 files 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", "<leader>afd", "<CMD>FormatDisable<CR>") +vim.keymap.set("n", "<leader>afD", "<CMD>FormatDisable!<CR>") +vim.keymap.set("n", "<leader>afe", "<CMD>FormatEnable<CR>") |
