nvim: edit chezmoi source files in their underlying language

This commit is contained in:
2026-06-05 01:58:57 +02:00
parent 08c87390c3
commit e713d2bac6
3 changed files with 41 additions and 4 deletions
+13
View File
@@ -5,6 +5,19 @@ end
-- Filetype detection
vim.filetype.add({ extension = { j2 = "jinja.html" } })
-- chezmoi templates: alker0/chezmoi.vim sets a compound `<base>.chezmoitmpl`
-- filetype and owns highlighting via merged base+go-template vim-syntax. Stop
-- treesitter (avoids a double-highlight conflict) and silence diagnostics so the
-- {{ }} regions aren't redlined as invalid base-language syntax.
vim.api.nvim_create_autocmd("FileType", {
group = augroup("chezmoi_templates"),
pattern = "*chezmoitmpl*",
callback = function(event)
pcall(vim.treesitter.stop, event.buf)
vim.diagnostic.enable(false, { bufnr = event.buf })
end,
})
-- Highlight on yank
vim.api.nvim_create_autocmd("TextYankPost", {
group = augroup("yank_highlight"),
+20
View File
@@ -0,0 +1,20 @@
-- Editing chezmoi source files (dot_*, *.tmpl) in their *underlying* language.
-- alker0/chezmoi.vim detects managed files under the source dir, resolves the
-- chezmoi naming (dot_foo → .foo) and the `.tmpl` suffix, sets the base
-- filetype, and merges go-template syntax over the {{ }} regions.
--
-- Pairs with:
-- • conform `.tmpl` skip (plugins/editing.lua) — formatters never corrupt templates
-- • the `chezmoitmpl` FileType guard (autocmds.lua) — stops treesitter highlight
-- (the plugin's vim-syntax owns templates) and silences {{ }} diagnostics
return {
{
"alker0/chezmoi.vim",
lazy = false, -- detection hooks must register before any source file opens
init = function()
-- required for reliable filetype detection under lazy.nvim
vim.g["chezmoi#use_tmp_buffer"] = true
vim.g["chezmoi#source_dir_path"] = vim.fn.expand("~/.local/share/chezmoi")
end,
},
}
+8 -4
View File
@@ -74,10 +74,14 @@ return {
end,
},
},
format_on_save = {
timeout_ms = 2000,
lsp_fallback = true,
},
format_on_save = function(bufnr)
-- Never run formatters on chezmoi templates: stylua/prettier/taplo would
-- choke on the {{ }} go-template syntax and corrupt the source file.
if vim.api.nvim_buf_get_name(bufnr):match("%.tmpl$") then
return
end
return { timeout_ms = 2000, lsp_fallback = true }
end,
},
},