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

13 views
Skip to first unread message

Dipayan

unread,
Mar 31, 2026, 3:39:32 PMMar 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 PMMar 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>

Christian Brabandt

unread,
Apr 3, 2026, 5:03:22 AMApr 3
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19877)

thanks. I fixed your message formatting. I assume this was done using AI?


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/c4182634064@github.com>

Dipayan

unread,
Apr 3, 2026, 8:26:28 AMApr 3
to vim/vim, Subscribed
dipayandutta left a comment (vim/vim#19877)

Hi @chrisbra I tried by myself. But in hurry did not check the precedence .
Thanks for the message.


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/c4183255430@github.com>

Christian Brabandt

unread,
Apr 3, 2026, 10:49:28 AMApr 3
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19877)

No worries. Can you please include a test case? Check the Test_listchars_foldcolumn() test inside testdir/test_listchars.vim which uses a screen dump test to verify the highlighting.


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/c4183785419@github.com>

Christian Brabandt

unread,
Apr 22, 2026, 12:51:46 PMApr 22
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19877)

I cannot see what is wrong with the current version. Can you give a reproducible example and what it should look like?

I tried to make a test of your repro, but it does not fail before/after your patch:

func Test_listchars_multispace_visual()
  CheckScreendump

  let lines =<< trim END
    set list
    set listchars=leadmultispace:\|\ \ \ ,eol:$
    set expandtab tabstop=4 shiftwidth=4
    highlight NonText ctermfg=1
    highlight Visual ctermbg=4
  END

  let py =<< trim END
  def foo():
      if True:
          pass
  END
  call writefile(lines, 'XTest_multispace', 'D')
  call writefile(py, 'Xfoobar.py', 'D')

  let buf = RunVimInTerminal('-S XTest_multispace Xfoobar.py', {'rows': 10, 'cols': 20})

  call term_sendkeys(buf, "gg0")
  call VerifyScreenDump(buf, 'Test_leadmultispace_01', {})
  call term_sendkeys(buf, "VG$")
  call VerifyScreenDump(buf, 'Test_leadmultispace_02', {})

  " clean up
  call StopVimInTerminal(buf)
endfunc

So how to see the difference?


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/c4298176438@github.com>

Maxim Kim

unread,
Apr 22, 2026, 10:53:30 PMApr 22
to vim/vim, Subscribed
habamax left a comment (vim/vim#19877)

So how to see the difference?

I believe Visual should set ctermfg to NONE to make it work.


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/c4301420500@github.com>

Christian Brabandt

unread,
Jun 13, 2026, 4:07:07 PM (13 hours ago) Jun 13
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#19877)

this has stalled, so closing


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

Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19877/c4699643955@github.com>

Reply all
Reply to author
Forward
0 new messages