dotfiles/dot_config/nvim/lua/plugins/format.lua

46 lines
1.1 KiB
Lua
Raw Permalink Normal View History

2024-04-28 08:07:29 +02:00
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" },
fish = { "fish_indent" },
2024-04-28 08:07:29 +02:00
perl = { "perltidy" },
python = { "isort", "black" },
javascript = { { "prettierd", "prettier" } },
sh = { "shfmt" },
2024-04-28 08:07:29 +02:00
},
-- Set up format-on-save
format_on_save = {
timeout_ms = 3000,
async = false,
quit = false,
lsp_fallback = true
},
2024-04-28 08:07:29 +02:00
-- 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,
}