From 9593ca249e4e93a449105cab4e28ec2eb0ff7b75 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 22 Apr 2026 08:57:02 +0800 Subject: [PATCH] vim-patch:10040bc: runtime(sh): allow "#" in special derefs Code like ${!#} flags the "#" as shDerefWordError [1]; the "!prefix" syntax region delegates to one of the shDerefSpecial handlers via @shDerefList, but it misses the "#" case as valid for ${##} and ${!#}. [1]: https://vi.stackexchange.com/q/48617/10604 Correct that. Indirection is only valid in Bash in Ksh, so rearrange the "!" handling to be conditional. closes: vim/vim#20016 Helped-by: Christian Brabandt https://github.com/vim/vim/commit/10040bc9cde340c52b5093cacb1d60fd2e621883 Co-authored-by: D. Ben Knoble --- runtime/syntax/sh.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/syntax/sh.vim b/runtime/syntax/sh.vim index 05eb488d53..d022059d72 100644 --- a/runtime/syntax/sh.vim +++ b/runtime/syntax/sh.vim @@ -24,6 +24,7 @@ " 2026 Feb 15 improve comment handling #19414 " 2026 Mar 23 improve matching of function definitions #19638 " 2026 Apr 02 improve matching of function definitions #19849 +" 2026 Apr 19 improve detection of special variables #20016 " }}} " Version: 208 " Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH @@ -751,13 +752,15 @@ endif if exists("b:is_bash") syn region shDeref matchgroup=PreProc start="\${!" end="\*\=}" contains=@shDerefList,shDerefOffset syn match shDerefVar contained "{\@<=!\h\w*" nextgroup=@shDerefVarList + syn match shDerefSpecial contained "\({!\)\@<=[[:alnum:]*#@_]\+" nextgroup=@shDerefVarList,shDerefOp endif if (exists("b:is_kornshell") && !exists("b:is_ksh88")) syn match shDerefVar contained "{\@<=!\h\w*[[:alnum:]_.]*" nextgroup=@shDerefVarList + syn match shDerefSpecial contained "\({!\)\@<=[[:alnum:]*#@_]\+" nextgroup=@shDerefVarList,shDerefOp endif syn match shDerefSpecial contained "{\@<=[-*@?0]" nextgroup=shDerefOp,shDerefOffset,shDerefOpError -syn match shDerefSpecial contained "\({[#!]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp +syn match shDerefSpecial contained "\({[#]\)\@<=[[:alnum:]*@_]\+" nextgroup=@shDerefVarList,shDerefOp syn match shDerefVar contained "{\@<=\h\w*" nextgroup=@shDerefVarList syn match shDerefVar contained '\d' nextgroup=@shDerefVarList if exists("b:is_kornshell") || exists("b:is_posix")