Skip to content

Commit dca3a7f

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 b83b2b0 commit dca3a7f

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
@@ -607,10 +607,16 @@ require('lazy').setup {
607607
'stevearc/conform.nvim',
608608
opts = {
609609
notify_on_error = false,
610-
format_on_save = {
611-
timeout_ms = 500,
612-
lsp_fallback = true,
613-
},
610+
format_on_save = function(bufnr)
611+
-- Enable format on save for specified filetypes
612+
local enable_filetypes = { 'lua' }
613+
if vim.tbl_contains(enable_filetypes, vim.bo[bufnr].filetype) then
614+
return {
615+
timeout_ms = 500,
616+
lsp_fallback = true,
617+
}
618+
end
619+
end,
614620
formatters_by_ft = {
615621
lua = { 'stylua' },
616622
-- Conform can also run multiple formatters sequentially

0 commit comments

Comments
 (0)