at dominant 1.4 kB view raw
1return { -- Autoformat 2 'stevearc/conform.nvim', 3 event = { 'BufWritePre' }, 4 cmd = { 'ConformInfo' }, 5 keys = { 6 { 7 '<leader>f', 8 function() 9 require('conform').format { async = true, lsp_format = 'fallback' } 10 end, 11 mode = '', 12 desc = '[F]ormat buffer', 13 }, 14 }, 15 opts = { 16 notify_on_error = false, 17 format_on_save = function(bufnr) 18 -- Disable "format_on_save lsp_fallback" for languages that don't 19 -- have a well standardized coding style. You can add additional 20 -- languages here or re-enable it for the disabled ones. 21 local disable_filetypes = { c = true, cpp = true } 22 if disable_filetypes[vim.bo[bufnr].filetype] then 23 return nil 24 else 25 return { 26 timeout_ms = 500, 27 lsp_format = 'fallback', 28 } 29 end 30 end, 31 formatters_by_ft = { 32 lua = { 'stylua' }, 33 -- Conform can also run multiple formatters sequentially 34 -- python = { "isort", "black" }, 35 -- 36 -- You can use 'stop_after_first' to run the first available formatter from the list 37 -- javascript = { "prettierd", "prettier", stop_after_first = true }, 38 }, 39 }, 40}