Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim Syntax: Fix Syntax Error shown on Vim 9.1 #10052

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oxzi
Copy link
Member

@oxzi oxzi commented Apr 30, 2024

There occurs a Vim syntax error on a fresh openSUSE Leap 15.5 system when trying to edit the Icinga 2 configuration. The specific packages were vim-9.1.0330-150500.20.12.1.x86_64, vim-icinga2-2.14.2-1.x86_64 and the following error was shown:

$ vim -R /etc/icinga2/conf.d/notifications.conf
Error detected while processing /usr/share/vim/vim91/suse.vimrc[10]../usr/share/vim/vim91/syntax/syntax.vim[44]..BufRead Autocommands for "/*etc/icinga2/*.conf"..FileType Autocommands for "*"..Syntax Autocommands for "*"..function <SNR>3_SynSet[25]..script /usr/share/vim/site/syntax/icinga2.vim: line  300:
E10: \ should be followed by /, ? or &
line  301:
E10: \ should be followed by /, ? or &
line  302:
E10: \ should be followed by /, ? or &
line  303:
E10: \ should be followed by /, ? or &
line  304:
E10: \ should be followed by /, ? or &
line  305:
E10: \ should be followed by /, ? or &
line  306:
E10: \ should be followed by /, ? or &
Press ENTER or type command to continue

ref/IP/53301

There occurs a Vim syntax error on a fresh openSUSE Leap 15.5 system
when trying to edit the Icinga 2 configuration. The specific packages
were vim-9.1.0330-150500.20.12.1.x86_64, vim-icinga2-2.14.2-1.x86_64 and
the following error was shown:

$ vim -R /etc/icinga2/conf.d/notifications.conf
Error detected while processing /usr/share/vim/vim91/suse.vimrc[10]../usr/share/vim/vim91/syntax/syntax.vim[44]..BufRead Autocommands for "/*etc/icinga2/*.conf"..FileType Autocommands for "*"..Syntax Autocommands for "*"..function <SNR>3_SynSet[25]..script /usr/share/vim/site/syntax/icinga2.vim:
line  300:
E10: \ should be followed by /, ? or &
line  301:
E10: \ should be followed by /, ? or &
line  302:
E10: \ should be followed by /, ? or &
line  303:
E10: \ should be followed by /, ? or &
line  304:
E10: \ should be followed by /, ? or &
line  305:
E10: \ should be followed by /, ? or &
line  306:
E10: \ should be followed by /, ? or &
Press ENTER or type command to continue
@oxzi oxzi added the ref/IP label Apr 30, 2024
@cla-bot cla-bot bot added the cla/signed label Apr 30, 2024
Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I did some research as I can't truly believe that a line continuation(\) is causing a Vim syntax error that has existed for literally decades. But after some testing and messing around with some vim configs, I was actually able to reproduce the exact error shown in the PR description.

First of all, vim would never be a ‘vim’ 😆 if a line continuation would cause a syntax error, and therefore, there must be some other strange things at play to cause such a disaster. Happily, I was able to track down the actual cause of this error, which is that vim only fails with a syntax error due to our syntax highlighting script when started in the OLD GNU vi compatible mode, which is on by default. Unfortunately, our highlighting script is not designed to work with vi, given that vi does not support syntax highlighting at all, so vim is falling apart badly.

Bildschirmfoto 2024-05-07 um 12 46 58
~/Workspace/icinga2 (master ✗) vim -R etc/icinga2/conf.d/services.conf
~/Workspace/icinga2 (master ✗) vim -CR etc/icinga2/conf.d/services.conf
Fehler beim Ausführen von "/Users/yhabteab/.vimrc[1]../opt/homebrew/Cellar/vim/9.1.0350/share/vim/vim91/syntax/syntax.vim[44]..BufRead Autokommandos für "/*etc/icinga2/*.conf"..FileType Autokommandos für "*"..Syntax Autokommandos für "*"..function <SNR>3_SynSet[25]..script /Users/yhabteab/.vim/syntax/icinga2.vim":
Zeile  300:
E10: \ sollte von /, ? oder & gefolgt werden
Zeile  301:
E10: \ sollte von /, ? oder & gefolgt werden
Zeile  302:
E10: \ sollte von /, ? oder & gefolgt werden
Zeile  303:
E10: \ sollte von /, ? oder & gefolgt werden
Zeile  304:
E10: \ sollte von /, ? oder & gefolgt werden
Zeile  305:
E10: \ sollte von /, ? oder & gefolgt werden
Zeile  306:
E10: \ sollte von /, ? oder & gefolgt werden
Betätigen Sie die EINGABETASTE oder geben Sie einen Befehl ein

Given all this, I was wondering why openSUSE doesn't set vim's incompatible mode system-wide in its vimrc file (/usr/share/vim/vim91/suse.vimrc) by default. Well, it does start vim with incompatible mode, but the flag is not set at the top of the file before anything else as recommended, instead it is set after turning on the syntax highlighting, which inevitably leads to this syntax error.

Thus, I have two possible methods of dealing with that problem. The first and easiest one is to simply create a vimrc file for the desired user and let vim automatically switch off compatible mode when starting it. The second option is to report the bug to openSUSE and wait for it to be fixed and manually edit the /usr/share/vim/vim91/suse.vimrc file as a temporary workaround. Nevertheless, I do not expect that we need to change our highlighting script in any way.

@oxzi
Copy link
Member Author

oxzi commented May 8, 2024

That's quite a bit of digging you've done there, thanks! Now it also made sense to my why I first wasn't able to reproduce this behavior on two very different systems with a Vim 9.1.:

default on, off when a vimrc or gvimrc file is found, reset in defaults.vim

As I had a .vimrc laying around, it was always off.

However, in the current state, installing the vim-icinga2 package on a vanilla openSUSE Leap 15.5 system1 results in Vim errors when one tries to edit some Icinga 2 configuration file. Unless we want to add some documentation (which nobody is going to read) stating this corner case, I would continue with this suggested change as it allows using our syntax also within an enabled compatible mode.

Footnotes

  1. Most probably also on older versions.

@yhabteab
Copy link
Member

yhabteab commented May 8, 2024

However, in the current state, installing the vim-icinga2 package on a vanilla openSUSE Leap 15.5 system1 results in Vim errors when one tries to edit some Icinga 2 configuration file.

The error does not necessarily depend on the used vim version, but is a pure openSUSE bug and exists in all supported versions.

" get easier to use and more user friendly vim defaults
" CAUTION: This option breaks some vi compatibility.
" Switch it off if you prefer real vi compatibility
set nocompatible

I would continue with this suggested change as it allows using our syntax also within an enabled compatible mode.

There is no syntax highlighting support when using vim with compatible mode and openSUSE also starts vim with incompatible mode, the flag set nocompatible just needs to be set before the syntax on command. I actually want to report this to openSUSE, but I'm a little confused where to even start. You can do it if you are familiar with their bug reporting procedure.

@oxzi
Copy link
Member Author

oxzi commented May 8, 2024

There is no syntax highlighting support when using vim with compatible mode

Really? I don't think that this is the case and the documentation also doesn't state this.

For example, I have just launched vim -C commands.conf, got a load of errors1, but afterwards a Vim with active syntax highlighting.

Footnotes

  1. Most from other plugins, which also don't like compatible.

@yhabteab
Copy link
Member

yhabteab commented May 8, 2024

Really? I don't think that this is the case and the documentation also doesn't state this.

My mistake, I was just reading this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants