From 1b73fe06fdf1306be77f88fc71884025eedbf921 Mon Sep 17 00:00:00 2001 From: Roman Date: Sun, 1 Nov 2026 22:49:27 +0100 Subject: [PATCH] toggle autoformatting --- nvim/.config/nvim/README.md | 1 + nvim/.config/nvim/lua/romanzy/keymaps.lua | 3 +++ .../nvim/lua/romanzy/plugins/conform.lua | 22 +++++++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/nvim/.config/nvim/README.md b/nvim/.config/nvim/README.md index d36c549..657ebe6 100644 --- a/nvim/.config/nvim/README.md +++ b/nvim/.config/nvim/README.md @@ -70,6 +70,7 @@ Toggle shortcuts: - `ti` toggle inline diagnostics - `tv` toggle virtual diagnostics - `th` — toggle the expanded hunk view +- `tf` — toggle auto formatting on save ## Terminal diff --git a/nvim/.config/nvim/lua/romanzy/keymaps.lua b/nvim/.config/nvim/lua/romanzy/keymaps.lua index 7b90727..8ba7493 100644 --- a/nvim/.config/nvim/lua/romanzy/keymaps.lua +++ b/nvim/.config/nvim/lua/romanzy/keymaps.lua @@ -33,6 +33,9 @@ map("n", "ts", require("romanzy.custom.spell").toggle, { desc = "toggle map("n", "th", function() MiniDiff.toggle_overlay() end, { desc = "toggle hunk view" }) +map("n", "tf", function() + require("romanzy.plugins.conform").toggle_autoformat() +end, { desc = "toggle autoformatting" }) map("n", "sv", "vs", { desc = "split vertical" }) map("n", "sh", "sp", { desc = "split horizontal" }) diff --git a/nvim/.config/nvim/lua/romanzy/plugins/conform.lua b/nvim/.config/nvim/lua/romanzy/plugins/conform.lua index c191f7a..ef81e5c 100644 --- a/nvim/.config/nvim/lua/romanzy/plugins/conform.lua +++ b/nvim/.config/nvim/lua/romanzy/plugins/conform.lua @@ -6,6 +6,7 @@ vim.pack.add({ }) local dart = require("romanzy.custom.dart") +local autoformat_enabled = true require("conform").setup({ formatters_by_ft = { @@ -34,8 +35,21 @@ require("conform").setup({ end, }, }, - format_on_save = { - lsp_format = "fallback", - timeout_ms = 2000, - }, + format_on_save = function() + if not autoformat_enabled then + return + end + + return { + lsp_format = "fallback", + timeout_ms = 2000, + } + end, }) + +return { + toggle_autoformat = function() + autoformat_enabled = not autoformat_enabled + vim.notify("Autoformatting " .. (autoformat_enabled and "enabled" or "disabled")) + end, +}