From 5758b3a32092f28897644562004632a2cca47201 Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Wed, 22 Oct 2025 12:29:10 +0200 Subject: [PATCH] fix(nvim): enable yaml syntax highlighting for sops files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../nb/modules/development/nvim/config/sops.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hosts/nb/modules/development/nvim/config/sops.lua b/hosts/nb/modules/development/nvim/config/sops.lua index 6d95957..662f09a 100644 --- a/hosts/nb/modules/development/nvim/config/sops.lua +++ b/hosts/nb/modules/development/nvim/config/sops.lua @@ -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