Use conform.nvim for fold-preserving formatting

This commit is contained in:
Alexander Gehrke 2024-04-04 18:18:22 +02:00
parent 855db2feee
commit b1e951ef1d
5 changed files with 52 additions and 17 deletions

37
lua/plugins/conform.lua Normal file
View file

@ -0,0 +1,37 @@
return {
"stevearc/conform.nvim",
event = { "BufWritePre" },
cmd = { "ConformInfo" },
keys = {
{
-- Customize or remove this keymap to your liking
"<leader>f",
function()
require("conform").format({ async = true, lsp_fallback = true })
end,
mode = "",
desc = "Format buffer",
},
},
-- Everything in opts will be passed to setup()
opts = {
-- Define your formatters
formatters_by_ft = {
lua = { "stylua" },
python = { "isort", "black" },
javascript = { { "prettierd", "prettier" } },
},
-- Set up format-on-save
format_on_save = { timeout_ms = 500, lsp_fallback = true },
-- Customize formatters
formatters = {
shfmt = {
prepend_args = { "-i", "2" },
},
},
},
init = function()
-- If you want the formatexpr, here is the place to set it
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
end,
}

View file

@ -1,11 +1,3 @@
return {
'mfussenegger/nvim-lint',
{
'mhartington/formatter.nvim',
opts = function()
return {
}
end
}
}