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