summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2026-04-22 08:57:02 +0800
committerzeertzjq <zeertzjq@outlook.com>2026-04-22 09:44:53 +0800
commit9593ca249e4e93a449105cab4e28ec2eb0ff7b75 (patch)
treebd9f18a9da3d031aad3936adad24bf10cee727dc
parentf0facb8fa4bf0026b6171bdf57c01af8569595ef (diff)
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 <cb@256bit.org> https://github.com/vim/vim/commit/10040bc9cde340c52b5093cacb1d60fd2e621883 Co-authored-by: D. Ben Knoble <ben.knoble+github@gmail.com>
-rw-r--r--runtime/syntax/sh.vim5
1 files changed, 4 insertions, 1 deletions
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")