Skip to main content
Topic: {,g}vim ignores shell comments at the end of lines that start with ^.*\s*set\s* (Read 841 times) previous topic - next topic
0 Members and 3 Guests are viewing this topic.

{,g}vim ignores shell comments at the end of lines that start with ^.*\s*set\s*

It looks like {,g}vim is hardcoded to ignore comments of the form
Code: [Select]
#!/bin/(ba)?sh
^.*\s*set\s*#\s*blabla$
The scrips in question are correct ("set -f #" is recognized as the start of
a comment by bash. "set", "set -- <arg>" and "set [-abefhkmnptuvxBCHP]" are valid
shell commands).

The problem is probably the following line in /usr/share/vim/vim81/syntax/sh.vim:
(line 408)
Code: [Select]
 syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/]" end="\ze[;|)]\|$"
which apparently can't be overridden with :syn commands (I tried). When I change
it to
Code: [Select]
 syn region shSetList oneline matchgroup=shSet start="\<set\>\ze[^/\ ]" end="\ze[;|)]\|$"
it seems to work, both with spaces and tabs. I can save the corrected file as
$HOME/.vim/syntax/sh.vim, and it will be used, but it seems like overkill to
replace an entire file just for one line. I just tried to file an issue at https://github.com/vim/vim/issues,
but it seems these are not for runtime issues.