[vim/vim] patch for listchars not using highlight groups in selection (PR #19877)

3 views
Skip to first unread message

Dipayan

unread,
Mar 31, 2026, 3:39:32 PM (yesterday) Mar 31
to vim/vim, Subscribed

Problem: When text with 'leadmultispace' (or other listchars whitespace
characters) is visually selected, the listchar characters do not
render with their designated highlight group (Whitespace/NonText).
They inherit the syntax color of surrounding text instead.
Solution: In win_line(), when attr_pri is set (Visual selection active),
combine extra_attr with char_attr using hl_combine_attr() instead
of skipping the assignment entirely.
fixes: #19872

pwd
/Users/dipayandutta/Developer/vim-official

cat /tmp/repro.vim
─────┬────────────────────────────────────────────────────────────────────────────────────
│ File: /tmp/repro.vim
─────┼────────────────────────────────────────────────────────────────────────────────────
1 │ set nocompatible
2 │ set list
3 │ set listchars=leadmultispace:|\ \ \ <----------
4 │ set expandtab tabstop=4 shiftwidth=4
5 │ highlight Whitespace ctermfg=1
6 │ highlight Visual ctermbg=4
─────┴────────────────────────────────────────────────────────────────────────────────────

cat /tmp/testfile.py
─────┬────────────────────────────────────────────────────────────────────────────────────
│ File: /tmp/testfile.py
─────┼────────────────────────────────────────────────────────────────────────────────────
1 │ def foo():
2 │ if True:
3 │ pass
─────┴───────────────────

src/vim -u /tmp/repro.vim /tmp/testfile.py
image.png (view on web)


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/19877

Commit Summary

  • 0f7c124 patch for listchars not using highlight groups in selection

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19877@github.com>

zeertzjq

unread,
Mar 31, 2026, 8:52:02 PM (24 hours ago) Mar 31
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/drawline.c:

> +		if (wlv.line_attr)
+		    wlv.char_attr = hl_combine_attr(wlv.line_attr,
+				hl_combine_attr(wlv.extra_attr, wlv.char_attr));
+		else
 #endif
-		wlv.char_attr = wlv.extra_attr;
+		    wlv.char_attr = hl_combine_attr(wlv.extra_attr, wlv.char_attr);

This gives char_attr higher priority than extra_attr, but previously only extra_attr is used. I wonder if it's better to give extra_attr higher priority instead:

⬇️ Suggested change
-		if (wlv.line_attr)
-		    wlv.char_attr = hl_combine_attr(wlv.line_attr,
-				hl_combine_attr(wlv.extra_attr, wlv.char_attr));
-		else
-#endif
-		wlv.char_attr = wlv.extra_attr;
-		    wlv.char_attr = hl_combine_attr(wlv.extra_attr, wlv.char_attr);
+		if (wlv.line_attr)
+		    wlv.char_attr = hl_combine_attr(wlv.line_attr,
+				hl_combine_attr(wlv.char_attr, wlv.extra_attr));
+		else
+#endif
+		    wlv.char_attr = hl_combine_attr(wlv.char_attr, wlv.extra_attr);


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19877/review/4041061938@github.com>

Reply all
Reply to author
Forward
0 new messages