[vim/vim] [Syntax highlighting] Vim comments are not detected correctly whenever a line has 2 double quotes (Issue #11560)

45 views
Skip to first unread message

Melandel

unread,
Nov 16, 2022, 2:49:38 PM11/16/22
to vim/vim, Subscribed

Steps to reproduce

  1. open your vimrc file
  2. write the lines
" Desktop Integration:-----------------{{{
" Plugins" ----------------------------{{{
" Graphical Layout:--------------------{{{
" Colorscheme, Highlight groups" ------{{{
  1. observe that the syntax highlighting is off

Expected behaviour

The written lines are highlighted as comments/commentLines

Version of Vim

9.0 with patch 1-887

Environment

gvim 64bits on Windows 10

Logs and stack traces

No response


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

Bram Moolenaar

unread,
Nov 16, 2022, 5:46:16 PM11/16/22
to vim/vim, Subscribed

This was discussed before: the double quotes make the text look like a string (which would be valid in Vim9 script, but we don't know in what type of script this is).
Just change those double quotes to colons and it looks OK. Any reason you don't want to do that?


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

cecamp

unread,
Nov 17, 2022, 12:14:33 AM11/17/22
to vim/vim, Subscribed

Closed #11560 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/11560/issue_event/7830302877@github.com>

cecamp

unread,
Nov 17, 2022, 12:14:35 AM11/17/22
to vim/vim, Subscribed

That's because the syntax highlighting sees "..." and interprets that as a string. Get rid of the double quote following the words Plugins and groups so they don't appear to be strings.


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

Bram Moolenaar

unread,
Nov 17, 2022, 8:26:28 AM11/17/22
to vim/vim, Subscribed


> That's because the syntax highlighting sees "..." and interprets that
> as a string. Get rid of the double quote following the words Plugins
> and groups so they don't appear to be strings.

I think this is the best compromise that we have now. Some users may
have spotted the non-comment highlighting when there is a double quote,
but I still haven't seen a good reason why that extra double quote was
there. Thus removing it fixes the problem, and avoid the bad
highlighting when a double quoted string is used in Vim9 script.

The ideal solution would be if we can somehow recognize those parts of a
script that are using Vim9 script syntax. Then we can highlight
comments properly, and also the user can quickly see when using the
wrong type of comment. The big question is: Can we reliable define a
region for Vim9 script?

When there is a "vim9script" line close to the top of the file, we can
start the Vim9 region. This does require syncing from the top, which
may make scrolling backwards a bit slow. Setting a maximum number of
lines (e.g. 500) is a compromise, not unusual for syntax highlighting.

Perhaps it's possible to define another region, which would be used if
we're not sure if we are in legacy or Vim9 script. In that region we
can try to highlight both, mostly like we do now.

Inside the Vim9 script region there can be ":function" commands, which
then uses the legacy script syntax. The vimFuncBody region already
exists, thus this should just work.

In legacy script there can be a ":def Func()" command. Currently this
is not recognized. It should start a Vim9 script region.

--
From "know your smileys":
~#:-( I just washed my hair, and I can't do nuthin' with it.

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

chdiza

unread,
Nov 17, 2022, 9:05:25 AM11/17/22
to vim/vim, Subscribed

See #11307, where @dkearns sketched a fix.

I still haven't seen a good reason why that extra double quote was there

Maybe not in the OP's particular example, but there is at least one good reason for this kind of thing: trailing comments, which are a real thing.

call SomeFunc() "Must do this or else XYZ

Obviously one might want to comment out the whole line for a variety of reasons. And if one does, the line ought to be highlighted as a comment.


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

Doug Kearns

unread,
Nov 17, 2022, 9:17:43 AM11/17/22
to vim/vim, Subscribed

That's because the syntax highlighting sees "..." and interprets that as a string. Get rid of the double quote following the words Plugins and groups so they don't appear to be strings.

I find that this highlighting issue turns up all the time and isn't really practical to work around. E.g., in comments with quotes and any commented out code with quotes (strings, patterns etc).

I appear to have some sort of fix for this as I haven't noticed the problem in some time.

It seems that, much as you described, I'm using regions for legacy and compiled functions and testing for "vim9script" when the syntax file is loaded. We could poll for that statement with the appropriate autocommands and then clear and add the appropriate syntax groups?

I'm currently testing a similar strategy in my Vim filetype plugin to change option settings for Vim9 and legacy script regions. It seems to work alright with CursorHold but I wasn't sure if that was too complicated to distribute.


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

Reply all
Reply to author
Forward
0 new messages