Add ConformDisable / ConformEnable commands

This commit is contained in:
Alexander Gehrke 2025-11-19 11:29:38 +01:00
parent 027118070c
commit e18c745662
2 changed files with 38 additions and 13 deletions

View file

@ -2,6 +2,25 @@ return {
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
init = function()
vim.api.nvim_create_user_command("ConformDisable", function(args)
if args.bang then
-- FormatDisable! will disable formatting just for this buffer
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("ConformEnable", function()
vim.b.disable_autoformat = false
vim.g.disable_autoformat = false
end, {
desc = "Re-enable autoformat-on-save",
})
end,
keys = {
{
-- Customize or remove this keymap to your liking
@ -24,6 +43,13 @@ return {
},
-- Set up format-on-save
--format_on_save = { timeout_ms = 500, lsp_fallback = true },
format_after_save = function(bufnr)
-- Disable with a global or buffer-local variable
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
return { timeout_ms = 500, lsp_format = "fallback" }
end,
-- Customize formatters
formatters = {
shfmt = {