From 58e86b84357f2329bbc57a413ca371a406d5be71 Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Thu, 26 Feb 2026 17:17:02 +0000 Subject: [PATCH] feat: Add highlight config for trailing white spaces in yaml files --- lua/plugins/astrocore.lua | 39 +++++++++++++++++++++++++++++++++++++++ lua/plugins/astroui.lua | 3 ++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lua/plugins/astrocore.lua b/lua/plugins/astrocore.lua index 3aa80d0..d5a14fd 100644 --- a/lua/plugins/astrocore.lua +++ b/lua/plugins/astrocore.lua @@ -35,6 +35,45 @@ return { [".*/etc/foo/.*"] = "fooscript", }, }, + -- Commands + commands = { + CleanYamlSpaces = { + function() + if vim.bo.filetype == 'yaml' or vim.bo.filetype == 'yml' then + local cursor_pos = vim.api.nvim_win_get_cursor(0) + vim.cmd([[%s/\s\+$//e]]) + vim.api.nvim_win_set_cursor(0, cursor_pos) + print("Espaces en fin de ligne supprimés") + else + print("Cette commande ne fonctionne que sur les fichiers YAML") + end + end, + desc = "Nettoie les espaces en fin de ligne dans les fichiers YAML", + }, + }, + -- Autocmd + autocmds = { + yaml_trailing_spaces = { + { + event = { "BufRead", "BufNewFile" }, + pattern = { "*.yaml", "*.yml" }, + callback = function() + vim.fn.matchadd("TrailingWhiteSpace", "\\s\\+$") + end, + desc = "Surligne les espaces en fin de ligne dans les fichiers YAML", + }, + { + event = "BufWritePre", + pattern = { "*.yaml", "*.yml" }, + callback = function() + local cursor_pos = vim.api.nvim_win_get_cursor(0) + vim.cmd([[%s/\s\+$//e]]) + vim.api.nvim_win_set_cursor(0, cursor_pos) + end, + desc = "Nettoie les espaces en fin de ligne avant sauvegarde", + }, + }, + }, -- vim options can be configured here options = { opt = { -- vim.opt. diff --git a/lua/plugins/astroui.lua b/lua/plugins/astroui.lua index 737a2fb..835a02c 100644 --- a/lua/plugins/astroui.lua +++ b/lua/plugins/astroui.lua @@ -1,4 +1,4 @@ -if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE +-- if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE -- AstroUI provides the basis for configuring the AstroNvim User Interface -- Configuration documentation can be found with `:h astroui` @@ -16,6 +16,7 @@ return { highlights = { init = { -- this table overrides highlights in all themes -- Normal = { bg = "#000000" }, + TrailingWhiteSpace = { bg = "red" }, }, astrodark = { -- a table of overrides/changes when applying the astrotheme theme -- Normal = { bg = "#000000" },