1

As title, how to get syntax highlighting for the embeded python within vimscript? Is there a plugin that does syntax highlighting for embeded script?

3
  • It should work out-of-the-box. See :h g:vimsyn_embed
    – Matt
    Mar 7, 2020 at 13:09
  • @Matt Thanks that worked!
    – Rui Liu
    Mar 7, 2020 at 13:39
  • 1
    @Matt can either turn that into an answer or OP can self-answer; let’s not leave it dangling in the comments
    – D. Ben Knoble
    Mar 7, 2020 at 14:18

1 Answer 1

1

So the enabled embedded syntaxes in VimScript are ruled by :h g:vimsyn_embed variable. However, Vim and Neovim has different default settings in this regard.

In Vim's syntax/vim.vim:

" Allows users to specify the type of embedded script highlighting
" they want:  (perl/python/ruby/tcl support)
"   g:vimsyn_embed == 0   : don't embed any scripts
"   g:vimsyn_embed =~# 'l' : embed lua      (but only if vim supports it)
"   g:vimsyn_embed =~# 'm' : embed mzscheme (but only if vim supports it)
"   g:vimsyn_embed =~# 'p' : embed perl     (but only if vim supports it)
"   g:vimsyn_embed =~# 'P' : embed python   (but only if vim supports it)
"   g:vimsyn_embed =~# 'r' : embed ruby     (but only if vim supports it)
"   g:vimsyn_embed =~# 't' : embed tcl      (but only if vim supports it)
if !exists("g:vimsyn_embed")
    let g:vimsyn_embed = "lmpPr"
endif

However, in Neovim the last but one line is changed to let g:vimsyn_embed = 0

Hence, let g:vimsyn_embed = 'P' must be added to init.vim to enable this feature in Neovim. While in Vim it should work by default.

Your Answer

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

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