disable autoformat with command
This commit is contained in:
parent
5e4822d8bb
commit
5e3db5028e
2 changed files with 29 additions and 0 deletions
26
init.lua
26
init.lua
|
@ -145,6 +145,32 @@ vim.opt.spellsuggest = 'double,50,timeout:5000'
|
|||
vim.api.nvim_create_user_command('Env', function(opts)
|
||||
vim.cmd(string.format('r!echo $%s', opts.fargs[1]))
|
||||
end, { nargs = 1 })
|
||||
vim.api.nvim_create_user_command('FormatDisable', function(args)
|
||||
if args.bang then
|
||||
-- FormatDisable! will disable formatting globally
|
||||
print 'disable autoformat globally'
|
||||
vim.g.disable_autoformat = true
|
||||
else
|
||||
print 'disable autoformat locally'
|
||||
vim.b.disable_autoformat = true
|
||||
end
|
||||
end, {
|
||||
desc = 'Disable autoformat',
|
||||
bang = true,
|
||||
})
|
||||
vim.api.nvim_create_user_command('FormatEnable', function(args)
|
||||
if args.bang then
|
||||
-- FormatDisable! will enable formatting globally
|
||||
print 'enable autoformat globally'
|
||||
vim.g.disable_autoformat = false
|
||||
else
|
||||
print 'enable autoformat locally'
|
||||
vim.b.disable_autoformat = false
|
||||
end
|
||||
end, {
|
||||
desc = 'Enable autoformat',
|
||||
bang = true,
|
||||
})
|
||||
|
||||
-- autocommands
|
||||
-- ===
|
||||
|
|
|
@ -22,6 +22,9 @@ return {
|
|||
opts = {
|
||||
notify_on_error = false,
|
||||
format_on_save = function(bufnr)
|
||||
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
||||
return
|
||||
end
|
||||
-- Disable "format_on_save lsp_fallback" for languages that don't
|
||||
-- have a well standardized coding style. You can add additional
|
||||
-- languages here or re-enable it for the disabled ones.
|
||||
|
|
Loading…
Add table
Reference in a new issue