diff --git a/dot_config/nvim/lua/autocmds.lua b/dot_config/nvim/lua/autocmds.lua index 2984c46..415e27f 100644 --- a/dot_config/nvim/lua/autocmds.lua +++ b/dot_config/nvim/lua/autocmds.lua @@ -5,6 +5,19 @@ end -- Filetype detection vim.filetype.add({ extension = { j2 = "jinja.html" } }) +-- chezmoi templates: alker0/chezmoi.vim sets a compound `.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"), diff --git a/dot_config/nvim/lua/plugins/chezmoi.lua b/dot_config/nvim/lua/plugins/chezmoi.lua new file mode 100644 index 0000000..2fa6266 --- /dev/null +++ b/dot_config/nvim/lua/plugins/chezmoi.lua @@ -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, + }, +} diff --git a/dot_config/nvim/lua/plugins/editing.lua b/dot_config/nvim/lua/plugins/editing.lua index b9f2476..1d0c080 100644 --- a/dot_config/nvim/lua/plugins/editing.lua +++ b/dot_config/nvim/lua/plugins/editing.lua @@ -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, }, },