[vim/vim] Bash/Sh Confused Syntax Highlighting reading .bashrc file (Issue #11977)

9 views
Skip to first unread message

pellea72

unread,
Feb 12, 2023, 8:50:40 AM2/12/23
to vim/vim, Subscribed

Steps to reproduce

  1. Compile and install latest master from git (as of this bug report).
  2. Open .bashrc file (vim ~/.bashrc)

image

Expected behaviour

The latest version of runtime/sh.vim (be4e016) breaks syntax highlighting, particularly with recognizing quoted text. It seems to be confused when quotes begin and end, and ends up treating code as quotes in some portions of the file. The previous version of runtime/sh.vim (86b4816) works fine as far as I can tell.

I've mainly tested it on a .bashrc file, but it has similar issues in some other bash files.

Version of Vim

Master (v 9.0 with patches 1-1303)

Environment

Linux debian-dell 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux

Logs and stack traces

No response


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977@github.com>

cecamp

unread,
Feb 12, 2023, 11:32:45 AM2/12/23
to vim/vim, Subscribed

Hmm, perhaps you could rectify some things, too. Please provide a (preferably short) example of the issue, don't send an image -- send text so I can test with it and not have to spend a lot of time re-typing it, and be clear about where the problem is. Thanks!


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1427074317@github.com>

Theodor

unread,
Feb 12, 2023, 11:38:53 AM2/12/23
to vim/vim, Subscribed

Hmm, perhaps you could rectify some things, too. Please provide a (preferably short) example of the issue, don't send an image -- send text so I can test with it and not have to spend a lot of time re-typing it, and be clear about where the problem is. Thanks!

I can also confirm that there was some kind of syntax highlighting bug after updating vim today.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1427075521@github.com>

Barnabás Ágoston

unread,
Feb 12, 2023, 11:44:35 AM2/12/23
to vim/vim, Subscribed

I also ran into a similar issue with the last vim update: VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Feb 11 2023 11:15:25)
image
This is how it looked with a previous VIM version: VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jan 12 2023 18:55:27)
image

And the example code:

#!/usr/bin/env bash
# args: since (e.g: 2 months)

set -euo pipefail

worktree=$(git rev-parse --show-toplevel --show-prefix | paste -sd/ -)
cd "$worktree"

git log --format= --name-only --since "${*:-1970}" --relative \
| sort \
| uniq -cd \
| sort -nk1 \
| tail -n 50


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1427076675@github.com>

pellea72

unread,
Feb 12, 2023, 12:11:55 PM2/12/23
to vim/vim, Subscribed

Hmm, perhaps you could rectify some things, too. Please provide a (preferably short) example of the issue, don't send an image -- send text so I can test with it and not have to spend a lot of time re-typing it, and be clear about where the problem is. Thanks!

Sure. The file starts out with comments in blue as usual, then when the code starts, almost everything is colored violet regardless of syntax purpose (except for a couple of small bits like punctuation), even through another set of comments, which should have gone back to being blue. But aside from comments later being colored blue in some places, it looks like it mostly disregards syntax rules and colors vast swaths of things violet.

Below I've pasted a portion of the text of the .bashrc file followed by a marked up version showing where colors start and stop using XML style color /color tags.

---------------------------------------------
.bashrc snippet:

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

-----------------------------

.bashrc snippet with <color> </color> tags:

<blue># ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything</blue>
<violet>case $- in
    *i*) <yellow>;;</yellow>
      *) <yellow>return;;</yellow>
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE<yellow>=</yellow><red>1000</red>
HISTFILESIZE<yellow>=</yellow><red>2000</red></violet>

<blue># check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.</blue>
<violet>shopt -s checkwinsize</violet>



Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1427083669@github.com>

John Tobin

unread,
Feb 12, 2023, 5:20:30 PM2/12/23
to vim/vim, Subscribed

Here's another example:

#!/bin/bash

set -e -f -u -o pipefail

update_one_dir() {
  if [[ ! -f ".pre-commit-config.yaml" ]]; then
    return
  fi
  pre-commit autoupdate
  if ! git check-local-copy-is-clean; then
    pre-commit run --all-files
    git commit -a -m 'Update hooks version.'
    git push
  fi
}

check-git-repos --pull_and_push "$(pwd)"
update_one_dir

Everything from line 9 (pre-commit autoupdate) through to line 17 (update_one_dir) is violet. The syntax of each line is shCmdSubRegion, whereas in an earlier version it was shFunctionOne or empty. In be4e016#diff-650e28e4ad6a5c9241345580a7136ff18b5629f3b4910a5b5a455828bca5e517R338 I see this diff at line 336/338:

 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(\ze[^(]"  skip='\\\\\|\\.' end=")"  contains=@shCommandSubList
 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(\ze[^(]\|$"  skip='\\\\\|\\.' end=")"  contains=@shCommandSubList

Reverting that line returns highlighting to normal.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1427147487@github.com>

pellea72

unread,
Feb 12, 2023, 5:42:12 PM2/12/23
to vim/vim, Subscribed

Here's another example:

#!/bin/bash

set -e -f -u -o pipefail

update_one_dir() {
  if [[ ! -f ".pre-commit-config.yaml" ]]; then
    return
  fi
  pre-commit autoupdate
  if ! git check-local-copy-is-clean; then
    pre-commit run --all-files
    git commit -a -m 'Update hooks version.'
    git push
  fi
}

check-git-repos --pull_and_push "$(pwd)"
update_one_dir

Everything from line 9 (pre-commit autoupdate) through to line 17 (update_one_dir) is violet. The syntax of each line is shCmdSubRegion, whereas in an earlier version it was shFunctionOne or empty. In be4e016#diff-650e28e4ad6a5c9241345580a7136ff18b5629f3b4910a5b5a455828bca5e517R338 I see this diff at line 336/338:

 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(\ze[^(]"  skip='\\\\\|\\.' end=")"  contains=@shCommandSubList
 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(\ze[^(]\|$"  skip='\\\\\|\\.' end=")"  contains=@shCommandSubList

Reverting that line returns highlighting to normal.

Good find. I meant to try reverting some of the changes, but I got sidetracked with some vimscript tutorials.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1427151683@github.com>

K.Takata

unread,
Feb 12, 2023, 10:01:54 PM2/12/23
to vim/vim, Subscribed

Have you tried sh.vim version 207 from @cecamp's website?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1427262843@github.com>

pellea72

unread,
Feb 13, 2023, 3:23:54 AM2/13/23
to vim/vim, Subscribed

Have you tried sh.vim version 207 from @cecamp's website?

I haven't tried it. But just putting the previous version of sh.vim into your home directory's .vim/syntax directory fixes the problem. Even doing that with the version of sh.vim that comes with Debian's vim works.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1427529286@github.com>

Kasper van der Heijden

unread,
Feb 13, 2023, 5:28:44 AM2/13/23
to vim/vim, Subscribed

A simple script also fails to highlight properly.

#!/usr/bin/env sh

var="${1}";

if [ -z "${var}" ]; then
    echo 'empty var';
fi

image


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1427696991@github.com>

Bram Moolenaar

unread,
Feb 13, 2023, 10:50:18 AM2/13/23
to vim/vim, Subscribed

@pellea72 please answer the question that @k-takata asked, we want to know if version 207 fixes this problem.
It's unlikely we would use a previous version if a newer version exists.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1428176041@github.com>

pellea72

unread,
Feb 13, 2023, 11:10:04 AM2/13/23
to vim/vim, Subscribed

Sorry, I didn't realize that was more recent than the version here on GitHub. Yes, his version 207 does seem to fix the problem.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1428212282@github.com>

pellea72

unread,
Feb 13, 2023, 11:10:58 AM2/13/23
to vim/vim, Subscribed

@pellea72 please answer the question that @k-takata asked, we want to know if version 207 fixes this problem. It's unlikely we would use a previous version if a newer version exists.

Sorry, I didn't realize that was more recent than the version here on GitHub. Yes, his version 207 does seem to fix the problem.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1428213833@github.com>

Dan Church

unread,
Feb 21, 2023, 12:45:13 PM2/21/23
to vim/vim, Subscribed

In be4e016#diff-650e28e4ad6a5c9241345580a7136ff18b5629f3b4910a5b5a455828bca5e517R338 I see this diff at line 336/338:

 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(\ze[^(]"  skip='\\\\\|\\.' end=")"  contains=@shCommandSubList
 syn region shCommandSub matchgroup=shCmdSubRegion start="\$(\ze[^(]\|$"  skip='\\\\\|\\.' end=")"  contains=@shCommandSubList

Reverting that line returns highlighting to normal.

Changing the start="\$(\ze[^(]\|$" to start="\$(\ze[^(]\?" fixes this issue as well, perhaps better than simply reverting the line.

With current syntax* With line reverted With my change
current code line reverted my change

* as of cfce5cf

Perhaps @cecamp would take this simple change instead of a revert.

Aside: Adding hi def link shCmdSubRegion Error helped me nail this down.

Here's the text of the script in the image
#!/bin/sh

case $- in
    *i*) ;;
    *) return;;
esac

# Comment

VAR=$(subshell)
VAR=$(
    multi-line
)
$( 
    multi-line
)
$(( arith ))
$((
    arith
))


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1438872673@github.com>

pellea72

unread,
Feb 27, 2023, 1:56:58 PM2/27/23
to vim/vim, Subscribed

Today's update to runtime/sh.vim fixed it. Thanks for your efforts.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/11977/1446882318@github.com>

pellea72

unread,
Feb 27, 2023, 1:57:05 PM2/27/23
to vim/vim, Subscribed

Closed #11977 as completed.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/11977/issue_event/8619203855@github.com>

Reply all
Reply to author
Forward
0 new messages