10

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. Commented Feb 18, 2023 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 ;-) Commented Feb 18, 2023 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
    Commented Feb 18, 2023 at 13:34
  • 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
    Commented Feb 18, 2023 at 14:00
  • 1
    I am guessing, this is the following issue, please try the linked workaround: github.com/vim/vim/issues/11937#issuecomment-1421116531 Commented Feb 21, 2023 at 10:05

3 Answers 3

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.

2
  • 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
    Commented Apr 5, 2023 at 18:03
  • I installed the brew install vim which has version of vim 9.1.0100 still have issues with bash, my entire code looks in the same color :/
    – Ricky Levi
    Commented Feb 26 at 12:02
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 Commented Feb 21, 2023 at 10:04
  • Welcome vi.SE @VladSavitsky. Downgrading will loose all other enhancements of newer version won't it? Weird.
    – gildux
    Commented Feb 21, 2023 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. Commented Feb 22, 2023 at 11:06
0

Upgrading vim didn't work for me ( version 9.1 mentioned in the comment above )

I ended up just updating the sh.vim file itself from the fix mentioned in

curl https://raw.githubusercontent.com/albertyw/dotfiles/e787d02d754883d02021811421906ce861a3b993/files/vim/syntax/sh.vim > ~/.vim/syntax/sh.vim

That worked for me

Your Answer

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

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