I copied the various existing files bash.vim, sh.vim, zsh.vim
(which I'm interested in) below my local $HOME/.vim
into their respective directories syntax, indent, and ftplugin .
Opening a local test file that contains (besides other things)
if [[ "$1" = "$2" ]]
...
x=$'\v'
the above two lines were marked as containing errors;
the final closing ] and the $' and terminating ' .
These errors vanish if I type these two commands consecutively
:set syntax=bash
:set syntax=sh
I wonder why that works but not a single :set syntax=sh alone.
(Is that due to some persisting side-effect from the bash setting?)
The errors also vanish if beforehand a #!/bin/ksh line is present.
My question (or request, if allowed) would be whether the correct
syntax highlighting for ksh syntax could be automatically detected
without the double-"set syntax" kludge or requiring a shebang line.
Thanks!
I'm also curious why for bash and zsh there's own :set syntax=...
possible but :set syntax=ksh disables syntax colors completely.
Janis
thanks for the explanation/history. - Some remarks below...
> On Do, 28 Mai 2026, Janis Papanagnou wrote:
>
> > I just cloned https://github.com/vim/vim.git
> >
> > I copied the various existing files bash.vim, sh.vim, zsh.vim
> > (which I'm interested in) below my local $HOME/.vim
> > into their respective directories syntax, indent, and ftplugin .
> >
> > Opening a local test file that contains (besides other things)
> >
> > if [[ "$1" = "$2" ]]
> > ...
> > x=$'\v'
>
> Traditionally, the vim sh filetype supports only the very narrow
> traditional (Bourne) syntax, not Bash, not ksh and not even POSIX
> syntax.
>
> However there were a few complaints over time, so a few heuristics have
> been built into the sh syntax script, which tries to guess what sh
> dialect is in use, e.g. by setting global variables or by inspecting the
> shebang line.
>
> I believe the above is not valid Bourne shell syntax, that's why you see
> those errors.
Yes, that is correct. (Actually Bourne shell 'sh' is meaningless nowadays.
The minimum expected standard is the POSIX Shell 'sh', based on ksh88.)
The [[...]] is syntax introduced by ksh(88) that is meanwhile supported
by all prominent shells, e.g. Ksh (88 and 93), Bash, and Zsh, and POSIX
at least "recognizes" that syntax.
The $'...' "ANSI strings" were introduced (I think) also by ksh (ksh93 in
this case) and is also supported by the prominent shells ksh, bash, zsh.
The points of my post were mainly that
* the double-set-syntax kludge showed an effect that was probably
an undesired side-effect that might need some attention; it could
be that these side effects are a key to make syntax highlighting
work also correctly for ksh (without that interactive kludge); I
mean, somehow it works then, so why not in the first place.
* correct highlighting of the syntax (invented by ksh and borrowed
by other shells) is provided but strangely not for Ksh (only for
Bash and Zsh it works; in zsh natively, and in bash by heuristics,
as I understand your explanations).
* given that there's syntax code/rules that are triggered for Bash
I'd have hoped that these could also be made to become effective
with Ksh.
Somehow it seems that the shell-heuristics detection seems to work for
bash but (strangely) isn't very good with ksh?
I'm lacking the Vim Syntax programming knowledge but maybe someone who
does may make something of above observations; to make ksh syntax work
as it already does with the mentioned kluge - which obviously doesn't
need any other heuristics than implicitly already present somewhere!
(It just doesn't get triggered initially. Why?)
> You can read about it a bit more at :h ft-sh-syntax
Thanks. I'll have another look to better understand the current state.
Janis
If I understand correctly you are suggesting to hard-configure the "used shell" by, say,
let g:is_kornshell= 1
But this (as it appears to me) would not be an appropriate solution to the problem.
The setting should not be depending on a single shell type that a user has to specify.
It shall depend on the actual shell *necessary* to parse _the given source codes_.
I am actually using different shells; sh (POSIX), bash (from others), and ksh (preferred).
All files should be correctly highlighted. And ideally by an heuristic, not by forcing the
user to change the operated items. But the (existing) heuristics seems not be sufficient.
(And, BTW, it's not about "mind-reading". - It's about keywords and syntax-reading.)
What I seem to currently have to do is either to explicitly set the syntax (ex-command),
or to specify a shebang line on each file (whether mine or third party), or maybe add
(or change) the file extension. - Usually I don't want (or am not allowed) to change the
file contents or its name.
All that is of course aside from the actual inherent issues with shell highlighting in Vim
that have been detected.
Janis
________________________________________
Von: vim...@googlegroups.com <vim...@googlegroups.com> im Auftrag von Charles Campbell <astro...@gmail.com>
Gesendet: Sonntag, 7. Juni 2026 15:12
An: vim...@googlegroups.com
Betreff: Re: AW: Highlighting problem with ksh syntax
Chip Campbell
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/3d7aa4be-ee65-faf0-bd05-51daff280d37%40gmail.com.