-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strange Syntax Highlighting Inside Bash Functions #213
Comments
Can this be reproduced with |
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:
I haven't yet investigated the reason for this distinction, and I'm not sure why Gruvbox Material defines only 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. |
Enabling Tree-sitter should be as simple as calling the module's |
Sweat, thank you for providing that link.
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.
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 This looks like a bug to me. When I clear the highlight group, shell functions in the form 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 |
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
: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.The text was updated successfully, but these errors were encountered: