Obscure shell syntax hifghlighting problem: Solved!

20 views
Skip to first unread message

J S

unread,
May 26, 2019, 5:40:30 AM5/26/19
to v...@vim.org
On 2019/05/21 13:17, someone replied thusly to 'J S' via vim_use wrote:
>> But is also allows the offset (and then length, too, but ignore that
>> for now) to be negative.  But, alas, as noted in "man bash", if the
>> offset is negative, you have to
>> put a space after the :, in order to avoid ambiguity with the usual
>> ${var:-xxx} construct.  So, you have to write:
>>
>> $ echo ${var: -9:5}
>>
>> Alas, vim flags this as an error.  If I take out the space before the
>> -, the highlighting is OK.  But with the space, it is flagged as error.
>>
>> Can this be fixed?

>Not that it fixes the syntax, but I've always used "${var:0-9:5}" so the field
>would clearly stand out as starting with an integer and not the ambiguous
>'dash'.  Is that flagged as an error too? 

Thank you!  Changing the space to a zero does both of these thngs:

1) Clears the VIM syntax highlighting error.

2) Does not change the bash functionality.

That zero works in bash is, of course, not mentioned in "man bash".  How did you figure that out?
Maybe I should take it up with the bash maintainer.

Paul

unread,
May 26, 2019, 5:52:49 AM5/26/19
to vim...@googlegroups.com
> That zero works in bash is, of course, not mentioned in "man bash".  How did you figure that out?Maybe I should take it up with the bash maintainer.

From the manual: "If offset evaluates to a number less than zero…"
signature.asc

John Little

unread,
May 30, 2019, 10:40:59 PM5/30/19
to vim_use
On Sunday, May 26, 2019 at 9:40:30 PM UTC+12, J S wrote:
> That zero works in bash is, of course, not mentioned in "man bash".
In the manual, in 3.5.3 Shell Parameter Expansion, it says:

In each of the cases below, word is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion.

"0-9" is seen as arithmetic. "1-10" would serve, too.

Regards, John Little

Reply all
Reply to author
Forward
0 new messages