✨ feat(format): add commands and keymap to toggle autoformat on save

This commit is contained in:
sankalp committed 2025-07-25 15:53:37 +05:45
1 parent 97c6fd5c81
commit 0352d71bcf
2 files changed
+30 -1

No files matched your search

+29
View File
@@ -25,6 +25,35 @@ conform.setup({
},
})
vim.api.nvim_create_user_command('FormatDisable', 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
vim.notify('Autoformat on save disabled', vim.log.levels.WARN)
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
vim.notify('Autoformat on save enabled', vim.log.levels.INFO)
end, {
desc = 'Re-enable autoformat-on-save',
})
-- Add keymap to disable and enable format on save
vim.keymap.set('n', [[\f]], function()
if vim.b.disable_autoformat or vim.g.disable_autoformat then
vim.cmd('FormatEnable')
else
vim.cmd('FormatDisable')
end
end, { desc = 'Toggle auto-format' })
-- Setup mason-conform
local auto_install = require('lib.util').get_user_config('auto_install', true)
local installed_formatters = require('plugins.list').formatter_sources or {}