9

Since recently my syntax highlighting for ft=sh (also syn=sh is set) is broken:

enter image description here

Why is that? How can I fix it?

Edit:

I'm using Vim 9.0 with patches 1-1302.

I add here the code from the screenshot. The code does not matter much, though. Syntax highlighting is broken for all my bash scripts that I checked. It seems to work for a few lines, before it breaks down.

#!/usr/bin/env bash

# Here is a comment. In yellow.

foo=bar
bar=baz
baz="${1}"

if [ "${foo}" == "bar" ]; then
    bar=foo
elif [ "${foo}" == "baz" ]; then
    bar=oof
fi

# Here is a comment. In green?

cd "$HOME"
mv x y
echo hello world

# Whatever I do, all is green.
10
  • 1
    I can reproduce your problem on Vim 9.0. It seems the problem is not on Vim 8.2. I suppose it deserve a big report in Vim. Feb 18 at 11:44
  • It would help if you could add the text of your script together with the screenshot. To reproduce the problem we gain a bit of time ;-) Feb 18 at 11:45
  • 1
    @VivianDeSmedt, I edited my post. Since you can reproduce the problem, would you suggest to open an issue on vim's github repository?
    – pfnuesel
    Feb 18 at 13:34
  • I can confirm that the syntax is fine in vim 8.1. A diff of syntax_checkers/sh/sh.vim shows no difference between the two versions though. Am I looking at the wrong file? Or does the issue lay elsewhere?
    – pfnuesel
    Feb 18 at 13:43
  • 1
    syntax_checkers/sh/sh.vim is part of ALE, which has nothing to do with syntax highlighting. Look for syntax/sh.vim instead, both in your own runtime and in the system one.
    – romainl
    Feb 18 at 14:00

2 Answers 2

6

It is a known bug which is fixed in the author's source code, see author's reply.

It should appear sometime in the future in main vim runtime.

1
  • I just did a brew upgrade vim and it solved the problem. The author's reply above notes this is fixed in 9.0.1400
    – KC Baltz
    Apr 5 at 18:03
0

Downgrade to 8.2 version of VIM because it's VIM9 bug (not ALE plugin bug):

mkdir ~/temp; 
git clone --branch v8.2.5172 https://github.com/vim/vim.git ~/temp/vim; 
cd ~/temp/vim;

make clean distclean
./configure --prefix=/usr --enable-python3interp=yes 
make -j4
# Install globally:
sudo make install
3
  • 2
    That is a drastic solution, most likely you just need to update the syntax script for sh files, see e.g. here: github.com/vim/vim/issues/11937#issuecomment-1421116531 Feb 21 at 10:04
  • Welcome vi.SE @VladSavitsky. Downgrading will loose all other enhancements of newer version won't it? Weird.
    – gildux
    Feb 21 at 10:09
  • 1
    For me it's more important to have working version of vim then to get enhancements of newer version so this is solution for cases like this. I have all I need in vim8 and do not loose anything with this downgrade. Feb 22 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.