Skip to content

Commit 3e7f2bb

Browse files
committed
conform: autoformat on save only for specified filetypes
Enable the autoformat on save only for specified filetypes. By default this is only for lua, similar as LSP is by default only enabled for lua. Based on conform recipe: https://github.com/stevearc/conform.nvim/blob/master/doc/recipes.md
1 parent 3cfccc0 commit 3e7f2bb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

init.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,10 +608,16 @@ require('lazy').setup({
608608
'stevearc/conform.nvim',
609609
opts = {
610610
notify_on_error = false,
611-
format_on_save = {
612-
timeout_ms = 500,
613-
lsp_fallback = true,
614-
},
611+
format_on_save = function(bufnr)
612+
-- Enable format on save for specified filetypes
613+
local enable_filetypes = { 'lua' }
614+
if vim.tbl_contains(enable_filetypes, vim.bo[bufnr].filetype) then
615+
return {
616+
timeout_ms = 500,
617+
lsp_fallback = true,
618+
}
619+
end
620+
end,
615621
formatters_by_ft = {
616622
lua = { 'stylua' },
617623
-- Conform can also run multiple formatters sequentially

0 commit comments

Comments
 (0)