From 4ea2eb23f4e6f4e30d66fdfa8d429bb6d2b40c4d Mon Sep 17 00:00:00 2001 From: Massimo Mund Date: Thu, 7 Aug 2025 21:46:42 +0200 Subject: [PATCH] Add a new colorscheme group for selections in hlsearch micro allows setting colors for selections and for search results. If a colorscheme defines a selection color that is very similar to the hlsearch highlight color, the currently selected text will hardly stand out during a highlighted search. So add a new color-group analogous to `statusline`, `statusline.inactive`, `statusline.suggestions`. --- internal/display/bufwindow.go | 9 ++++++++- runtime/help/colors.md | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index ddbb044c7b..49a1366a3a 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -622,7 +622,8 @@ func (w *BufWindow) displayBuffer() { } if highlight { - if w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) { + highlightSearchMatch := w.Buf.HighlightSearch && w.Buf.SearchMatch(bloc) + if highlightSearchMatch { style = config.DefStyle.Reverse(true) if s, ok := config.Colorscheme["hlsearch"]; ok { style = s @@ -648,6 +649,12 @@ func (w *BufWindow) displayBuffer() { if s, ok := config.Colorscheme["selection"]; ok { style = s } + + if highlightSearchMatch { + if s, ok := config.Colorscheme["hlsearch.selection"]; ok { + style = s + } + } } if b.Settings["cursorline"].(bool) && w.active && !preservebg && diff --git a/runtime/help/colors.md b/runtime/help/colors.md index 9a139fbc43..f48d6d92a5 100644 --- a/runtime/help/colors.md +++ b/runtime/help/colors.md @@ -203,6 +203,8 @@ Here is a list of the colorscheme groups that you can use: * error-message (Color of error messages in the bottom line of the screen) * match-brace (Color of matching brackets when `matchbracestyle` is set to `highlight`) * hlsearch (Color of highlighted search results when `hlsearch` is enabled) +* hlsearch.selection (Color of the selection within highlighted search + results when `hlsearch` is enabled) * tab-error (Color of tab vs space errors when `hltaberrors` is enabled) * trailingws (Color of trailing whitespaces when `hltrailingws` is enabled)