[vim/vim] highlight SpecialKey and NonText (Issue #12472)

252 views
Skip to first unread message

Passw

unread,
May 30, 2023, 8:01:59 PM5/30/23
to vim/vim, Subscribed

Steps to reproduce

  1. rm -rf ~/.vimrc
  2. gvim testfile // tesfile should contains tab,eol
  3. set list lcs=tab:→\ ,space:·,nbsp:␣,eol:¶
  4. highlight SpecialKey guifg=red gui=NONE
  5. highlight NonText guifg=green gui=NONE

Expected behaviour

tab and eol should be with guifg=red
but tab with guifg=red, eol with guifg=green
image

Version of Vim

with the latest vim downloaed via choco install vim

Environment

gvim under Windows

Logs and stack traces

Another things I found that highlight **SpecialKey** and **NonText** behavior different between vim and nvim

## vim
- `:help SpecialKey`

							*hl-SpecialKey*
SpecialKey	Meta and special keys listed with ":map", also for text used
		to show unprintable characters in the text, 'listchars'.
		Generally: Text that is displayed differently from what it
		really is.
  • :help NonText
NonText		'@' at the end of the window, "<<<" at the start of the window
		for 'smoothscroll', characters from 'showbreak' and other
		characters that do not really exist in the text, such as the
		">" displayed when a double-wide character doesn't fit at the
		end of the line.

nvim

  • :help SpecialKey
							*hl-SpecialKey*
SpecialKey	Unprintable characters: Text displayed differently from what
		it really is. But not 'listchars' whitespace. |hl-Whitespace|
  • :help NonText
							*hl-NonText*
NonText		'@' at the end of the window, characters from 'showbreak'
		and other characters that do not really exist in the text
		(e.g., ">" displayed when a double-wide character doesn't
		fit at the end of the line). See also |hl-EndOfBuffer|.

vim treats both keys listed with :map and listchars as SpecialKey. Sometimes we want color of listchars lighter (since tab,eol in source code should be lighter), but with keys listed with :map with darker color.

Personally I prefer nvim's solution to SpecialKey (without listchars) and NonText


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

Christian Brabandt

unread,
May 31, 2023, 2:08:39 AM5/31/23
to vim/vim, Subscribed

I might be missing something, but Vim is exactly behaving like what is documented, isn't it? I am sure, if we change it, people will also complain, so that may not be the best idea.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12472/1569552598@github.com>

Passw

unread,
May 31, 2023, 4:05:36 AM5/31/23
to vim/vim, Subscribed

Hi, @chrisbra

I think both tab and eol are listchars. And according :help SpecialKey, the color of all listchars are set by highlight SpecialKey guifg=red gui=NONE. It should be expected that both tab and eol are in Red color. But it seems that the color of eol is indicated by setting of NonText which is green.

About the difference between vim and nvim, it's a suggestion that I think vim can take into consideration.

  • :help listchars
						*'listchars'* *'lcs'*
'listchars' 'lcs'	string	(default "eol:$")
			global or local to window |global-local|
	Strings to use in 'list' mode and for the |:list| command.  It is a
	comma-separated list of string settings.
							*lcs-eol*
	  eol:c		Character to show at the end of each line.  When
			omitted, there is no extra character at the end of the
			line.
							*lcs-tab*
	  tab:xy[z]	Two or three characters to be used to show a tab.
			The third character is optional.

        ...


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12472/1569694906@github.com>

Christian Brabandt

unread,
May 31, 2023, 4:37:22 AM5/31/23
to vim/vim, Subscribed

yes, but there is a difference between unprintable characters in the text and characters that do not really exist in the text. So in this case it makes sense to distinguish between NonText and SpecialKey, because the eol char is not really there in the text.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12472/1569746740@github.com>

Passw

unread,
May 31, 2023, 6:47:30 AM5/31/23
to vim/vim, Subscribed

Thanks for you explanation.
From this perspective, I can understand why color of eol is green.

But I think it is a little bit confusion that not all listchars with the same color.
And keys listed with :map and some of listchars have the same color is not a good choice.
In pracice, I would set color of tab in lighter color (without setting any other listchars) than the normal source code, but this setting will also cause keys listed with :map in lighter color which is not what I wanted.

Anyway, this should not a bug, just an improvement or suggestion.

Thanks for your time.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12472/1569956492@github.com>

Passw

unread,
May 31, 2023, 6:47:31 AM5/31/23
to vim/vim, Subscribed

Closed #12472 as completed.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/12472/issue_event/9388646820@github.com>

Passw

unread,
May 31, 2023, 11:10:43 AM5/31/23
to vim/vim, Subscribed

In case someone has interest in this.

Just add a link to nvim's implementation about adding new higlight ground Whitespace for listchars

[RDY] new highlight group Whitespace for 'listchars'

nvim

  • :help hl-Whitespace
							*hl-Whitespace*
Whitespace	"nbsp", "space", "tab", "multispace", "lead" and "trail"
		in 'listchars'.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12472/1570422746@github.com>

Bram Moolenaar

unread,
Jun 1, 2023, 5:01:52 AM6/1/23
to vim/vim, Subscribed


> In case someone has interest in this.
>
> Just add a link to nvim's implementation about adding new higlight ground **Whitespace** for `listchars`
>
> [[RDY] new highlight group Whitespace for 'listchars' ](https://github.com/neovim/neovim/pull/6367)
>
> ### nvim
> - `:help hl-Whitespace`

> ```
> *hl-Whitespace*
> Whitespace "nbsp", "space", "tab", "multispace", "lead" and "trail"
> in 'listchars'.
> ```

This sounds like a partial solution. Soon someone wants one of the
items to be highlighted differently. E.g. to make "trail" look more
like an error. For a better solution a more drastic change is needed,
that also takes care of characters displayed when 'list' is not set.
The 'listchars' option clearly has outgrown it's original purpose.

--
I AM THANKFUL...
...for the mess to clean after a party because it means I have
been surrounded by friends.

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/12472/1571641128@github.com>

Reply all
Reply to author
Forward
0 new messages