I have been using neovim for several months with basically no issue and enjoying it very much. I have recently started receiving a problem with the syntax highlighting in Rust.

When the file first loads, it uses the syntax defined in the $VIMRUNTIME/syntax/rust.vim file from rust.vim, which is what I want, but after a few seconds (probably once rust-analyzer loads and runs), it changes the highlighting to use different colours (there's probably a better way to describe it, but a video is easier to show). This colour change also happens when I write the file (and rust-analyzer runs again).

The problem only happens in Rust, and I'm 99% sure that it's due to rust-analyzer and its semantic highlighting. I believe it's rust-analyzer because when remove it from my init.vim, the problem does not persist.

I've spent quite a bit of time attempting to find a solution to this problem, but I've found nothing.

What I've tried thus far:

  • Upgrading rust-analyzer
  • Downgrading rust-analyzer
  • Upgrading neovim
  • Downgrading neovim
  • I've also tried different methods of installation for both rust-analyzer and neovim on various versions of each
  • Removing everything from my init.vim to the point where there was only rust-analyzer and the lsp
  • Manually change the highlighting rules while the file is open using :hi <group> ...
    • This had no effect even when using the highlight group that the token was supposed to be

Some notes:

  • My init.vim can be found here
  • I am using Arch Linux
  • A video of the issue can be found here
  • When using this mapping, the highlight token does not ever change
    • furthermore, when I looked up the highlight group showed in :hi, it did not have the same style as the one in the document, (i.e. rustModPath was blue in :hi, but showed as purple in the rust file)
    • :syn had the same issue as above
    • SyntaxAttr gave the same token with the same problems

1 Answer 1


The solution was really simple, I was just being dumb.

The doc shows how to disable it: https://neovim.io/doc/user/lsp.html#lsp-semantic-highlight:

-- Hide semantic highlights for functions
vim.api.nvim_set_hl(0, '@lsp.type.function', {})
-- Hide all semantic highlights
for _, group in ipairs(vim.fn.getcompletion("@lsp", "highlight")) do
 vim.api.nvim_set_hl(0, group, {})
  • 1
    Maybe could you explain it in your answer. Apr 19, 2023 at 4:28
  • 1
    Sure! Updated the answer. Apr 20, 2023 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.