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, but I imagine many or most when interpreting syntax definitions, including the onekeyword elements.
The syntax file for filetype=sh
, will assume that does set a specific :syn iskeyword
(thanks @ChristianBrabandt for pointing it out!) But it uses the globalvalue of the 'iskeyword'
will be sanesetting in its definition. (It uses the :syn iskeyword
command to add -
and include delimiters such as _:
to a keyword definition for syntax purposes.)
You can useoverride the :syn keyword
command to fix this issuedefinition by creating a new syntax/sh.vim
file in your local Vim after/
directory (~/.vim/after/syntax/sh.vim
, or ~/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, asand also includes the one to use when parsingmodifications of the shipped syntax keywords for the sh
filetype.
You may also decide to add more characters that should be considered as keyword characters forwhich adds sh-
syntaxand (such as "-") in your local definition:
.