0

The gruvbox colorscheme and syntax highlighting for C++ doesn't highlight some elements such as:

  • string
  • vector

I have this:

enter image description here

So I decided to change the colors manually using in init.vim

syn keyword Type string
syn keyword Type vector

This method didn't work.

When I run these commands myself while editing a file, I get the following change:

enter image description here

enter image description here

It works like a charm:

enter image description here

My goal is to automatically change colors for string, vector, cout and many more keywords from init.vim, because by default they are not highlighted by gruvbox.

  • neovim version (nightly-nvim from AUR):
NVIM v0.5.0-dev+1391-g1df8a34a7
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
  • neofetch:

enter image description here

In init.vim I have:

filetype plugin indent on
syntax on

I have also tried the after-directory option. I placed a new file called after_init.vim in these directories:

  • ~/.config/nvim/after/after_init.vim
  • ~/.config/nvim/after/syntax/after_init.vim
  • ~/.vim/after/after_init.vim
  • ~/.vim/after/syntax/after_init.vim

with:

syn keyword Type string
syn keyword Type vector
echon "im loaded after init.vim"

This also did not work.

I then also tried the autocommand option in init.vim:

augroup ft_c
    autocmd!
    autocmd Syntax c syn keyword Type string
    autocmd Syntax c syn keyword Type vector
augroup end

This didn't work.

D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65
alexzander
  • 113
  • 6

1 Answers1

2

The files in the syntax directory should be named after the filetype detected by Vim. In the case of your C++ code, I'd expect it would detect it as cpp. You can check that with the following command:

:set filetype?
cpp

Or you can use :set ft? for short.

Once you confirm that the filetype is indeed cpp, you can create file ~/.vim/after/syntax/cpp.vim (for Vim) or ~/.config/nvim/after/syntax/cpp.vim (for NeoVim) with the syn commands you want to load after the built-in rules are loaded:

syn keyword Type string
syn keyword Type vector
filbranden
  • 28,785
  • 3
  • 26
  • 71