This behavior is happening because your
'iskeyword' did not include "_" as a valid keyword character when the syntax was first loaded.
The syntax for
sh (among many other languages) use the
:syn keyword command to define syntax based on keywords, and where the keywords are recognized (regarding the delimiters around them) depends on the
'iskeyword' setting by default.
To track down where "_" was removed from
'iskeyword', you can find where it was last set with the following command:
:verbose set iskeyword?
This should show you the current setting (where you'll notice it's missing
_ in the list) and also the file and line number of the script where it was last set (which hopefully will be the place where
_ was removed.)
If you fix it back with
:set iskeyword+=_, you'll still have to reload the syntax (easiest is by using
:set ft=sh) for it to highlight the keywords correctly.
There is also a
:syn iskeyword command to override the global
'iskeyword' settings when interpreting syntax keyword elements.
The syntax file for
filetype=sh does set a specific
:syn iskeyword (thanks @ChristianBrabandt for pointing it out!) But it uses the value of the
'iskeyword' setting in its definition. (It uses the
:syn iskeyword command to add
: to a keyword definition for syntax purposes.)
You can override the
:syn keyword definition by creating a new
syntax/sh.vim file in your local Vim
after/ directory (
~/config/nvim/after/syntax/sh.vim for NeoVim), with the following line in its contents:
syntax iskeyword @,48-57,_,192-255,-,:
This hardcodes the default
'iskeyword' settings, which include the "_" as a keyword character, and also includes the modifications of the shipped syntax for
sh which adds