sh/bash syntax highlighting broken (sometimes) for comments.

Offen
#22,001 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 13 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
57/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
bash, shell, vim

Rechercherichtung

The highlighting rules live in runtime/syntax/sh.vim; start by reading the shComment definitions and the regions that contain them (the if/then block and command-name matching for echo), since the false match appears only where those clusters apply. Reproduce with the sample script saved as a file and opened via vim --clean file.sh, then narrow the trigger line by line. Check src/testdir/test_syntax.vim for how syntax regressions are asserted, and treat "no line after # highlighted" on the sample as done.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug
Steps to reproduce

open this file with vim and see that the syntax highlighting sometimes consider the text after # to be a comment and sometimes not:

#!/bin/sh

# only echo seems to be affected
echo hello# world
printf hello# world
foo hello# world

# these only are affected within an `if` statement?
foo "$@"# || uhoh
foo-bar "$@"# || uhoh

if true; then
	foo "$@"# || uhoh
	foo-bar "$@"# || uhoh
fi

in the above script there are actually 0 inline comments according to bash - it just looks like there are according to vim.

attached is a screenshot of this file in vim --clean, notice that it falsely highlights inline comments for echo, or when inside the if block:

Screenshot 2026-11-22 at 6 41 06 PM

Note I originally found this when testing a bash script but it appears to affect sh as well.

Expected behaviour

I expect that none of the lines in the above script will have any inline comments highlighted.

Version of Vim

9.2 1-1393

Environment

OS: macOS 27.0.1, vim installed with homebrew

$ uname
Darwin
$ echo $TERM
xterm-256color
$ echo $0
-bash
$ type vim
vim is hashed (/opt/homebrew/bin/vim)
$ vim --version
VIM - Vi IMproved 9.2 (2026 Feb 14, compiled Nov 22 2026 20:28:41)
macOS version - arm64
Included patches: 1-1393
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl                +find_in_path       -mouseshape         -tag_old_static
+arabic             +float              +multi_byte         -tcl
+autochdir          +folding            +multi_lang         +termguicolors
+autocmd            -footer             -mzscheme           +terminal
-autoservername     +fork()             +netbeans_intg      +terminfo
-balloon_eval       +gettext            +num64              +termresponse
+balloon_eval_term  -hangul_input       +packages           +textobjects
-browse             +iconv              -pango              +textprop
++builtin_terms     -image              +path_extra         +timers
+byte_offset        -image_popup        +perl               +title
+channel            +insert_expand      +persistent_undo    -toolbar
+cindent            +ipv6               +popupwin           +user_commands
+clientserver       +job                +postscript         +vartabs
+clipboard          +jumplist           +printer            +vertsplit
+clipboard_provider +keymap             +profile            +vim9script
+cmdline_compl      +lambda             -python             +viminfo
+cmdline_hist       +langmap            +python3/dyn        +virtualedit
+cmdline_info       +libcall            +quickfix           +visual
+comments           +linebreak          +reltime            +visualextra
+conceal            +lispindent         +rightleft          +vreplace
+cryptv             +listcmds           +ruby/dyn           -wayland
+cscope             +localmap           +scrollbind         -wayland_clipboard
+cursorbind         +lua/dyn            +signs              +wildignore
+cursorshape        +menu               +smartindent        +wildmenu
+dialog_con         +mksession          +socketserver       +windows
+diff               +modify_fname       +sodium             +writebackup
+digraphs           +mouse              +sound              -X11
-dnd                +mouse_dec          +spell              -xattr
-ebcdic             -mouse_gpm          +startuptime        -xfontset
+emacs_tags         -mouse_jsbterm      +statusline         -xim
+eval               +mouse_netterm      -sun_workshop       -xpm
+ex_extra           +mouse_sgr          +syntax             -xsmp
+extra_search       -mouse_sysmouse     +tabpanel           -xterm_clipboard
-farsi              +mouse_urxvt        -tag_any_white      -xterm_save
+file_in_path       +mouse_xterm        +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
 3rd user vimrc file: "~/.config/vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/opt/homebrew/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -Wl,-rpath,@loader_path/../../../../opt/lua/lib -Wl,-rpath,@loader_path/../../../../opt/[email protected]/lib -Wl,-rpath,@loader_path/../../../../opt/ruby/lib -o vim -lm -lncurses -lsodium -liconv -lintl -framework AppKit -fstack-protector-strong -L/System/Library/Perl/5.34/darwin-thread-multi-2level/CORE -lperl
$

the sh syntax file said it was looking for a maintainer so hopefully opening the issue here is the right place.

Vorherrschende Sprache
Vim Script
Sterne
41.4k
Forks
6.2k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus vim/vim

Alle Issues in vim/vim

Ähnliche Issues

Weitere Issues zu DevTools

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.