synax highlighting anomaly

11 views
Skip to first unread message

Dave McCooey

unread,
Sep 25, 2022, 4:38:45 AM9/25/22
to vim...@vim.org
Hello,

There is a problem with syntax highlighting in "rc" files (e.g. _vimrc).

I am using the following commands to highlight tabs:

:hi Tab ctermbg=235
autocmd BufWinEnter * syntax match Tab /\t/ containedin=ALL

This works as expected in file types like .c, .html, .js, and .java.

In "rc" files, however, a tab is not highlighted when it is preceded
by a string consisting entirely of decimal digits (e.g. 55, 123, 9000).
Adding spaces between the number string and the tab does not
change the behavior - the tab is still not highlighted.

The ftplugin files are the default ones included in the distribution.

This problem is seen with vim version 8.2 (included patches 1-4372)
on Cygwin, and also with version 8.2 (included patches 1-2072) on Linux.

I have version 7.3 running on a Mac that does not have the problem.

Best regards,
Dave McCooey

Christian Brabandt

unread,
Sep 25, 2022, 11:37:39 AM9/25/22
to vim...@vim.org
Can you please provide a reproducible example? Also, it is not clear
what kind of an rc file you are using (and there are various rc
filetypes available, like muttrc and fetchmailrc, so I need something
reproducible).

I tried with something silly like foobar.rc and do not see the problem
in there using:

vim --clean -c ':hi Tab ctermbg=235' --cmd 'autocmd BufWinEnter * syntax
match Tab /\t/ containedin=ALL' foobar.rc


Best,
Christian
--
Debian Tipp #11: Bleiben Sie auf dem laufenden - lesen sie die wöchentlichen
Debian-Nachrichten! Lesen Sie sie im Web unter
http://www.debian.org/News/weekly/, oder abonieren Sie
debian-ne...@lists.debian.org.

Dave McCooey

unread,
Sep 25, 2022, 1:21:30 PM9/25/22
to vim...@googlegroups.com, vim...@vim.org
Hi Christian,

The file with the problem is _vimrc itself, which is how I noticed it.

Here is a line from my _vimrc that shows the problem:

:hi Tab ctermbg=235\t" Grey19 = 0x303030

The \t is really a single tab character.

My assumption that _vimrc is an "rc" file appears to be wrong,
because if I copy _vimrc to xxx.rc, then xxx.rc does not have the problem.

Best regards,
Dave McCooey

--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/20220925153728.GA1155360%40256bit.org.

Christian Brabandt

unread,
Sep 26, 2022, 9:38:29 AM9/26/22
to vim...@googlegroups.com, vim...@vim.org

On So, 25 Sep 2022, Dave McCooey wrote:

> Hi Christian,
>
> The file with the problem is _vimrc itself, which is how I noticed it.
>
> Here is a line from my _vimrc that shows the problem:
>
> :hi Tab ctermbg=235\t" Grey19 = 0x303030
>
> The \t is really a single tab character.
>
> My assumption that _vimrc is an "rc" file appears to be wrong,
> because if I copy _vimrc to xxx.rc, then xxx.rc does not have the problem.

I have been digging around the vim syntax file a bit. At some point, the
vimNumber syntax definition added the 'skipwhite' argument to it, which
basically prevents that the whitespace after it can be matched by other
syntax rules.

In your case, I would change the BufWinEnter autocommand to a matchadd()
function call like this:

au BufWinEnter *.vim call matchadd('Tab', '\t')

Then it should be working again.

Thanks,
Chris
--
Wer sich frei entfalten will, muß viele Ratschläge in den Wind
schlagen können.
-- Werner Mitsch

Dave McCooey

unread,
Sep 27, 2022, 12:56:17 AM9/27/22
to vim...@googlegroups.com, vim...@vim.org
On Mon, Sep 26, 2022 at 8:38 AM Christian Brabandt <cbl...@256bit.org> wrote:

On So, 25 Sep 2022, Dave McCooey wrote:

> Hi Christian,
>
> The file with the problem is _vimrc itself, which is how I noticed it.
>
> Here is a line from my _vimrc that shows the problem:
>
> :hi Tab ctermbg=235\t" Grey19 = 0x303030
>
> The \t is really a single tab character.
>
> My assumption that _vimrc is an "rc" file appears to be wrong,
> because if I copy _vimrc to xxx.rc, then xxx.rc does not have the problem.

I have been digging around the vim syntax file a bit. At some point, the
vimNumber syntax definition added the 'skipwhite' argument to it, which
basically prevents that the whitespace after it can be matched by other
syntax rules.

In your case, I would change the BufWinEnter autocommand to a matchadd()
function call like this:

au BufWinEnter *.vim call matchadd('Tab', '\t')

Then it should be working again.

Thanks for diagnosing the problem and for the work-around.

I had looked at matchadd() but was unsure about whether
clearmatches() needs to be called when leaving a window.
If I don't call it, then when I enter and leave a window repeatedly,
do the matches accumulate with repeated calls to matchadd()?

Best regards
Dave McCooey 

 
Reply all
Reply to author
Forward
0 new messages