6

A moderator on Vi & Vim SE recently announced syntax highlighting for lang-vimscript (seems to be synonymous to lang-vim) to be working: It looks like lang-vimscript is supported for code highlighting

When we tried out (take a look at the edit history), we noticed some errors, especially regarding comments. Comments in Vimscript start with double quotes " and are terminated by end of line. What we saw was "zebra highlighting" with every other line highlighted as a string. This is misleading and awkward to read.

A look at page source confirmed every other line marked as hljs-string.

screenshot of inspector showing every other line with class hljs-string

The situation is the same on SO (and probably any other SE site with syntax highlighting).

There's an issue in highlight.js that was fixed in 2016. When trying with an up-to-date version of highlight.js, Vimscript comments are (mostly) correctly highlighted as hljs-comment. Somebody must have updated in six years so this can't be it.

There's no lang-vim or lang-vimscript in the list of supported languages so I assume whatever we see is not actually highlight.js rendering Vimscript but something else.

What is it? And more importantly, could we just enable highlight.js' vim.js instead?

1 Answer 1

6

You were really close– you can always see what highlighting language HL.js is using by looking at what class it uses for the <code> element inside the block's respective <pre> tag:

Screenshot of the HTML markup of the code block

In this case, despite the user-defined language being lang-vimscript, we can see that HL.js is actually using csharp.

Another thing you can look to is the browser console, where HL.js will warn if a code block on the page is using an unrecognized language hint:

Screenshot of the console in the browser devtools pane, with two warning messages from HL.js visible

WARN: Could not find the language 'vimscript', did you forget to load/include a language module?
WARN: Falling back to no-highlight mode for this block. <code class=​"hljs language-csharp">​…​</code>​

Despite the second message saying it's falling back to "no-highlight mode", Stack Exchange has the default configured to be HL.js' "best guess" for the language instead... but it only gets to pick languages that Stack has chosen to enable.

Given that Vim isn't in that list, there aren't any right answers, and so your mileage varies depending on what it feels is "closest" for that particular block; it ended up being C# in this case.

The reason it does this, rather than telling the user directly that the hint is unsupported, is its own can of worms.


As for adding Vim as a supported language, that sounds super sensible– there's an entire site for it after all!

Unfortunately, the company de facto deferred all language support requests starting about 2 years ago, when Julia syntax highlighting was asked for.

You're more than welcome to make a formal request for it, but my impression is that it won't be delivered anytime soon.


Related reading:

2
  • 2
    Thank you for your detailed and enlightening answer. You mention making a "formal request", how would I do that? I'll keep my expectations low but features that are never asked for are never implemented.
    – Friedrich
    Nov 7, 2023 at 6:56
  • 3
    "... features that are never asked for are never implemented." Here at StackExchange, that's just not a true statement.
    – ouflak
    Nov 7, 2023 at 7:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .