fix(nvim): enable yaml syntax highlighting for sops files

Add BufReadPre autocmd to set filetype=yaml before buffer is loaded,
ensuring syntax highlighting works immediately when opening encrypted
sops files. Also updated BufReadPost to unconditionally set yaml
filetype after decryption.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-22 12:29:10 +02:00
parent 7d2f818fca
commit 5758b3a320

View File

@@ -19,6 +19,16 @@ local function is_secrets_file(filepath)
return false
end
-- Set filetype before reading to enable syntax highlighting
vim.api.nvim_create_autocmd("BufReadPre", {
group = sops_group,
pattern = secrets_patterns,
callback = function(args)
-- Set filetype to yaml before the file is read so syntax highlighting works
vim.bo.filetype = "yaml"
end,
})
-- Decrypt file after reading
vim.api.nvim_create_autocmd("BufReadPost", {
group = sops_group,
@@ -50,10 +60,8 @@ vim.api.nvim_create_autocmd("BufReadPost", {
vim.bo.writebackup = false
vim.bo.undofile = false
-- Set filetype to yaml if not already set
if vim.bo.filetype == "" then
vim.bo.filetype = "yaml"
end
-- Ensure filetype is set to yaml for syntax highlighting
vim.bo.filetype = "yaml"
vim.notify("SOPS: File decrypted successfully", vim.log.levels.INFO)
else