diff --git a/lua/plugins/lang/conform.lua b/lua/plugins/lang/conform.lua index 5659d91..4143048 100644 --- a/lua/plugins/lang/conform.lua +++ b/lua/plugins/lang/conform.lua @@ -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 {} diff --git a/lua/plugins/ui/which-key.lua b/lua/plugins/ui/which-key.lua index 9963c64..904c712 100644 --- a/lua/plugins/ui/which-key.lua +++ b/lua/plugins/ui/which-key.lua @@ -63,7 +63,7 @@ local normal_mappings = { { 'cc', ':CccHighlighterToggle', desc = 'Highlight Colors' }, { 'cd', ':RootDir', desc = 'Root Directory' }, { 'ce', ':%SnipRun', desc = 'Execute File' }, - -- { 'cf', ':lua vim.lsp.buf.format({async = true})', desc = 'Format File' }, + { 'cf', ':lua vim.lsp.buf.format({async = true})', desc = 'Format File' }, { 'cl', '::g/^\\s*$/d', desc = 'Clean Empty Lines' }, { 'cm', ':MarkdownPreviewToggle', desc = 'Markdown Preview' }, { 'co', ':Dashboard', desc = 'Dashboard' },