From dca3a7f8b9b87d7742ac406f3cb9b82a55186f59 Mon Sep 17 00:00:00 2001 From: Damjan 9000 Date: Mon, 4 Mar 2024 22:45:44 +0100 Subject: [PATCH] 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 --- init.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index 16d3c26..dffae4a 100644 --- a/init.lua +++ b/init.lua @@ -607,10 +607,16 @@ require('lazy').setup { 'stevearc/conform.nvim', opts = { notify_on_error = false, - format_on_save = { - timeout_ms = 500, - lsp_fallback = true, - }, + format_on_save = function(bufnr) + -- Enable format on save for specified filetypes + local enable_filetypes = { 'lua' } + if vim.tbl_contains(enable_filetypes, vim.bo[bufnr].filetype) then + return { + timeout_ms = 500, + lsp_fallback = true, + } + end + end, formatters_by_ft = { lua = { 'stylua' }, -- Conform can also run multiple formatters sequentially