toggle autoformatting

This commit is contained in:
2026-11-01 22:49:27 +01:00
parent b7810da99e
commit 1b73fe06fd
3 changed files with 22 additions and 4 deletions
+1
View File
@@ -70,6 +70,7 @@ Toggle shortcuts:
- `<leader>ti` toggle inline diagnostics
- `<leader>tv` toggle virtual diagnostics
- `<leader>th` — toggle the expanded hunk view
- `<leader>tf` — toggle auto formatting on save
## Terminal
@@ -33,6 +33,9 @@ map("n", "<leader>ts", require("romanzy.custom.spell").toggle, { desc = "toggle
map("n", "<leader>th", function()
MiniDiff.toggle_overlay()
end, { desc = "toggle hunk view" })
map("n", "<leader>tf", function()
require("romanzy.plugins.conform").toggle_autoformat()
end, { desc = "toggle autoformatting" })
map("n", "<leader>sv", "<Cmd>vs<CR>", { desc = "split vertical" })
map("n", "<leader>sh", "<Cmd>sp<CR>", { desc = "split horizontal" })
@@ -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 = {
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,
}