I created a test file by launching Neovim using nvim --clean test.vim, then verified the filetype was vim using set ft. Then I set let g:vimsyn_embed='l'. However the following file is still highlighted incorrectly:

lua << EOF
  local lspconfig = require('lspconfig')
  lspconfig.pyright.setup {}
  lspconfig.tsserver.setup {}
  lspconfig.rust_analyzer.setup {}

Do I need to do something else to get g:vimsyn_embed to work? I read that it worked for other people a few years ago (https://www.reddit.com/r/neovim/comments/j3xmf3/how_can_i_highlight_lua_code_in_a_usual_vim_file/) and that this option was even enabled by default in 2021 (https://github.com/neovim/neovim/pull/14213).

2 Answers 2


I wasn't able to get g:vimsyn_embed to work, but here's what I did instead:

  1. Install nvim-treesitter.
  2. In ~/.config/nvim/after/queries/vim/injections.scm, put:
; extends
    (body) @injection.content)
  (#set! injection.language "lua"))

The comment is required. Otherwise the file will override your Treesitter configuration instead of extending it.

I'm happy to accept another answer if someone actually gets g:vimsyn_embed to work.

  • Injection of Lua highlight from vimscript is configured by default in nvim-treesitter, so I think you don't need step 2 here. Just install nvim-treesitter and it should work out of box. Commented Jan 14 at 13:48
  • It doesn’t work out of the box for me on the stable release or on HEAD. Commented Jan 15 at 19:30

This is a bug of vim syntax engine and syntax file (hence neovim shares the same issue): https://github.com/neovim/neovim/issues/20456

Using treesitter for Vimscript and Lua syntax highlighting will be much recommended.

  • vim isn’t installed on my computer. Commented Jan 15 at 19:31
  • You got it wrong. I mean, neovim inherits from vim, so the bug of vim also affects neovim. Read the issue. Commented Jan 16 at 22:24
  • 1
    It's not only a bug of Vim, but also a bug of Neovim. And a patch would be appreciated :) Commented Jan 17 at 12: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.