Closed StrangeRanger closed 1 month ago
Can this be reproduced with :colorscheme default
?
At least with the default colorscheme for my version of neovim
, no:
Note that I reset my init.vim
to the minimum settings before using :colorscheme default
:
call plug#begin(stdpath('data') . '/plugged')
Plug 'sainnhe/gruvbox-material'
call plug#end()
colorscheme gruvbox-material
I just tried locally and got the same result as you did.
The behavior comes from Vim's syntax. The Vim syntax has two highlight groups for the body of shell functions:
shFunctionOne
for the short form (1st example in your snippet)shFunctionTwo
for the long formI haven't yet investigated the reason for this distinction, and I'm not sure why Gruvbox Material defines only shFunctionOne
(and why Green instead of Normal), but I'll try to provide you with an answer and possible fix.
As an aside: Tree-sitter is much more accurate that Vim's syntax. Since you seem to have the grammar for Bash installed, is there any reason why you are not using Tree-sitter highlights?
I wasn't aware that I wasn't using the tree-sitter syntax highlighting. I thought it just as simple as installing the plugin and neovim would default to using it. I'll look into how to enable it. Would using the tree-sitter syntax potentially fix this problem, or is this problem more with the gruvbox-theme?
Enabling Tree-sitter should be as simple as calling the module's setup()
function (a common pattern among Lua plugins). And yes, it should eliminate the problem you are seeing, although we should probably still consider fixing the Vim syntax because Gruvbox Material supports Vim as well as Neovim.
Enabling Tree-sitter should be as simple as calling the module's setup() function (a common pattern among Lua plugins).
Sweat, thank you for providing that link.
And yes, it should eliminate the problem you are seeing, although we should probably still consider fixing the Vim syntax because Gruvbox Material supports Vim as well as Neovim.
That makes sense. I don't think I can help with much due to my limited knowledge, but please let me know if there is anything I can do to help.
With that said, this question may be out of the scope of the current conversation, but how does neovim-treesitter use gruvbox-material compared to Vim? It obviously uses it differently, as the issue isn't a problem with Treesetter and how some things are colored differently, but I'd like to know how it can do that while using the same code base. Are there just different rules for each "syntax parsing method" provided by Vim and Treesetter?
Happy to clarify: all a (Neo)vim colorscheme does is associate a set of well known highlight groups with a certain combination of background/foreground colors and, optionally, a style such as bold or italic.
The "legacy" Vim syntax is fairly disorganized, with every filetype plugin potentially dictating its own conventions:
The Neovim Tree-sitter syntax, on the other hand, follows a much more structured convention, with highlight groups easily recognizable with their @
prefix:
Both of these syntaxes do the same thing: they parse the buffer and associate certain segments of it (e.g. strings, variables, functions, ...) with a suitable highlight group. By associating highlight groups for both Vim and Tree-sitter to concrete colors, Gruvbox Material can effectively support both highlight methods.
As you can imagine, Tree-sitter is much easier to get right due to its strong conventions which are lacking in legacy Vim. Most modern colorschemes don't bother providing per-language customizations for Vim, and I can't blame them for not doing it 🙂
Oh, ok. That makes sense. Thanks for taking the time to explain that.
@sainnhe do you happen to remember why shFunctionOne
links to GreenBold
, while shFunctionTwo
is cleared?
This looks like a bug to me. When I clear the highlight group, shell functions in the form name() { ... }
are highlighted the same way as functions in the form function name { ... }
, which I believe is expected. I couldn't spot any other side effect, and looking at Vim's syntax/bash.vim doesn't quite help me because I'm unfamiliar with the regular expression style used by Vim.
Note also that I haven't found customizations for this highlight group in other Vim color schemes, outside of Everforest, Edge and Sonokai (I checked ~10 of the most popular ones).
@antoineco This seems to be a bug, and I also forget why I linked shFunctionOne
to GreenBold
. Looks like this highlight link can be safely removed.
I have done the following steps before reporting this issue:
Operating system/version
macOS Sonoma 14.6.1
Terminal emulator/version
Terminal.app (Version 2.14 (453))
$TERM environment variable
xterm-256color
Tmux version
No response
Feature matrix
Minimal vimrc that can reproduce this bug.
Steps to reproduce this bug using minimal vimrc
.sh
or.bash
as the extension:touch tmp.bash
nvim tmp.bash
Paste the following code into the file:
:w
Expected behavior
When creating a function in Bash, with or without the
function
keyword, the syntax highlighting is the same as if the code were outside the function.Actual behavior
When creating a Bash function without the
function
keyword, some text is highlighted in an "olive green-looking" color instead of the standard "light-yellowish white-looking" color. But when I specify thefunction
keyword, the syntax highlighting works as it should.