Skip to content

Commit 63d58df

Browse files
committed
conform: disable autoformat on save for specified filetypes
Provide a method to disable autoformat on save for specified filetypes. By default disable for C/C++ as an example, because it does not have a well standardized coding style. Based on conform recipe: https://github.com/stevearc/conform.nvim/blob/master/doc/recipes.md
1 parent 7892c0c commit 63d58df

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

init.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,19 @@ require('lazy').setup({
603603
'stevearc/conform.nvim',
604604
opts = {
605605
notify_on_error = false,
606-
format_on_save = {
607-
timeout_ms = 500,
608-
lsp_fallback = true,
609-
},
606+
format_on_save = function(bufnr)
607+
-- Disable "autoformat on save" for languages that don't have
608+
-- a well standardized coding style. You can add additional
609+
-- languages here or re-enable it for the disabled ones.
610+
local disable_filetypes = { 'c', 'cpp' }
611+
if vim.tbl_contains(disable_filetypes, vim.bo[bufnr].filetype) then
612+
return
613+
end
614+
return {
615+
timeout_ms = 500,
616+
lsp_fallback = true,
617+
}
618+
end,
610619
formatters_by_ft = {
611620
lua = { 'stylua' },
612621
-- Conform can also run multiple formatters sequentially

0 commit comments

Comments
 (0)