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.

You can read about it a bit more at :h ft-sh-syntax

Note: zsh is a separate filetype and comes with its own syntax rules. It 
does in no way depend on the sh syntax.  ksh however does not have it's 
own filetype but uses the sh syntax script.

> 
> 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.

Some time ago, it was suggested to make bash its own independent 
filetype, but this has caused a bit of backlash, mainly for being 
backwards incompatible, so we went back to the sh filetype by default 
(and kept the unusual configuration via heuristics and additional global 
vim variables).

Best,
Christian
-- 
Something's rotten in the state of Denmark.
                -- Shakespeare

-- 
-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/ahiNp/AyYApwZBoL%40256bit.org.

Raspunde prin e-mail lui