feat: use conform for easier formatting

This commit is contained in:
2025-11-12 09:03:02 +01:00
parent 6865b4f655
commit 755ec71e01

View File

@@ -18,6 +18,7 @@ vim.pack.add({
{ src = "https://github.com/neovim/nvim-lspconfig" },
{ src = "https://github.com/sainnhe/everforest" },
{ src = "https://github.com/nvim-lualine/lualine.nvim" },
{ src = "https://github.com/stevearc/conform.nvim" },
-- autoclosing tags
{ src = "https://github.com/windwp/nvim-ts-autotag" },
@@ -267,29 +268,22 @@ vim.api.nvim_create_autocmd('TextYankPost', {
end,
})
vim.api.nvim_create_autocmd('BufWritePost', {
desc = 'Autoformat code on safe with prettier',
pattern = '*.html',
callback = function()
local filepath = vim.fn.expand('%:p')
vim.fn.system({ 'npx', 'prettier', '--write', filepath })
vim.cmd('edit!')
end,
require("conform").setup({
formatters_by_ft = {
html = { "prettier" },
},
default_format_opts = {
lsp_format = "fallback",
},
})
vim.api.nvim_create_autocmd('BufWritePre', {
desc = 'Autoformat code on save with lsp',
desc = 'Autoformat code on save',
pattern = '*',
callback = function()
local filetype = vim.bo.filetype
if filetype == "html" then
return
end
vim.lsp.buf.format({ async = false })
callback = function(args)
require("conform").format({ bufnr = args.buf })
end,
})
vim.filetype.add({ extension = { templ = "templ" } })