[vim/vim] Incorrect Bash highlighting after array declaration (Issue #18712)

8 views
Skip to first unread message

zeertzjq

unread,
Nov 10, 2025, 8:30:29 AM (yesterday) Nov 10
to vim/vim, Subscribed
zeertzjq created an issue (vim/vim#18712)

Steps to reproduce

  1. Run vim --clean.
  2. Open the following Bash script file:
#!/bin/bash
echo foo
declare -A bar=(
  [\(\)]="baz"
)
echo ${bar[\(\)]}
  1. The echo on the last line is highlighted as shArrayValue.

Expected behaviour

The echo on the last line is highlighted as shStatement, like the echo on the second line.

Version of Vim

9.1.1888

Environment

Operating system: Arch Linux

Logs and stack traces


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/18712@github.com>

zeertzjq

unread,
Nov 10, 2025, 8:35:21 AM (yesterday) Nov 10
to vim/vim, Subscribed
zeertzjq left a comment (vim/vim#18712)

This has been happening since 48fa319. However the behavior before that commit may also be incorrect.


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/18712/3511695392@github.com>

Aliaksei Budavei

unread,
Nov 10, 2025, 6:53:52 PM (yesterday) Nov 10
to vim/vim, Subscribed
zzzyxwvut left a comment (vim/vim#18712)

The shEscape business is beyond my ken. Unlike " or ' that
run in couples, \\* have no balanced counterpart to look
for. An escaped character or a series of characters that
form a unit ought to be matched and coloured in some manner.
After the escaped character of a series is claimed, the
remaining characters are fair game for further matching.

I tentatively suggest this change:

diff --git a/runtime/syntax/sh.vim b/runtime/syntax/sh.vim
index 5cf493065..be1ea1840 100644
--- a/runtime/syntax/sh.vim
+++ b/runtime/syntax/sh.vim
@@ -603,7 +603,7 @@ syn match  shVariable	"\<\h\w*\ze="			nextgroup=shVarAssign
 if exists("b:is_bash")
     " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)".
     syn region  shArrayValue	contained	start="\[\%(..\{-}\]=\)\@=" end="\]=\@="	contains=@shArrayValueList nextgroup=shVarAssign
-    syn cluster shArrayValueList	contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,bashSpecialVariables,shParenError
+    syn cluster shArrayValueList	contains=shArithmetic,shArithParen,shCommandSub,shDeref,shDerefSimple,shExpr,shNumber,shExSingleQuote,shExDoubleQuote,shSingleQuote,shDoubleQuote,shSpecial,shParen,bashSpecialVariables,shParenError,shEscape
     syn region  shArrayRegion	contained matchgroup=shShellVariables start="(" skip='\\\\\|\\.' end=")" contains=@shArrayValueList,shArrayValue,shComment
 elseif (exists("b:is_kornshell") && !exists("b:is_ksh88"))
     " The subscript form for array values, e.g. "foo=([2]=10 [4]=100)".

(This would break up a series in testdir/input/sh_12.vim.)

On the other hand:

syn clear shEscape

and resorting to paired quoting is another way to deal with
it.


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/18712/3514385566@github.com>

Reply all
Reply to author
Forward
0 new messages