简体   繁体   中英

NeoVim: Broken Syntax Highlighting after heredoc "lua << EOF" in VimScript

I'm facing the problem that my init.vim becomes not highlighted properly after the line with lua << EOF in NeoVim. The weird behaviour is 1) paired brackets are colored differently; 2) After lua << EOF a Lua context does begin, yet it doesn't seem to be ended after the next EOF , instead it continues being highlighted in a Lua syntax (all lines later on are affected). From the screenshot below you can see that the brackets in line 59 are displayed as white and red separately, and the Lua syntax stays after line 60.

在此处输入图像描述

The code itself is assumed as okay, since it can be sourced without any error or warning, and the editing functions normally. It should namly only be a problem with the highlighting.

Sadly I can't tell the context of this problem. I first noticed it today without doing anything special (eg installing a new plugin) and I'm not sure when it occured. I have no clue what is causing this, even after doing research on Google for more than one hour - I haven't seen any post describing a similar situation.

The problem remains with the default color scheme.

I was guessing the CoC extension coc-vimlsp could be relevant, but the problem remains after I disabled it. Otherwise I can't remember any NeoVim plugin that could have something to do with the highlighting.

EDIT: I noticed that the broken highlighting after EOF is relevant to the broken brackets. If I write no brackets in the heredoc block, the highlighting will work correctly. Looks like the Lua highlighting remains after the heredoc block because it thinks the brackets aren't closed properly. And this is only about round brackets () , other brackets like [] {} "" would cause no problem.

My init.vim :

" Indentation
set shiftwidth=4
set ai 
set si

" Show line numbers
set nu

" Show command at the bottom right of the screen
set sc

" Limit the number of items shown in popup
set ph=20

" Set the minimal number of lines below the cursor
set so=15

" Disable auto comment insertion
au Filetype * setlocal fo-=c fo-=o fo-=r

" vim-plug config
call plug#begin()
    " Themes
    Plug 'catppuccin/nvim', {'as': 'catppuccin'}
    Plug 'tiagovla/tokyodark.nvim'

    " Icon support
    Plug 'ryanoasis/vim-devicons'

    " Statusbar
    Plug 'nvim-lualine/lualine.nvim'

    " Fish support
    Plug 'dag/vim-fish'

    " Makrdown support
    Plug 'preservim/vim-markdown'

    " Markdown preview
    Plug 'iamcco/markdown-preview.nvim', { 'for': ['markdown', 'vim-plug'] }

    " TeX support
    Plug 'lervag/vimtex'

    " Auto close XML-like tags
    Plug 'alvan/vim-closetag'

    " Auto close brackets
    Plug 'jiangmiao/auto-pairs'
    
    " CoC completion engine
    Plug 'neoclide/coc.nvim', { 'branch': 'release' }
call plug#end()

" catppuccin config
let g:catppuccin_flavour = "mocha" " latte, frappe, macchiato, mocha

lua << EOF
require("catppuccin").setup()
EOF

" Set colorscheme
colorscheme catppuccin

" lualine config
lua << EOF
require('lualine').setup({
    options = {
    theme = "horizon"
    }
})
EOF

" vim-markdown config
let g:tex_conceal = ""
let g:vim_markdown_math = 1
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_frontmatter = 1
let g:vim_markdown_new_list_item_indent = 0

" Enable vimtex for Markdown files
" Not ideal, since this enables ALL features of vimtex
au Filetype md,markdown call vimtex#init()

" VimTeX config
let g:vimtex_compiler_latexmk = {'continuous': 0}

" CoC config
exe 'so ~/.config/nvim/coc_config.vim'

Operating system: MacOS Monterey 12.4

Output of nvim -v :

NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Monterey

Features: +acl +iconv +tui
See ...

The issue raised in both of Neovim and Vim repository.

Neovim side: https://github.com/neovim/neovim/issues/20456

Vim side: https://github.com/vim/vim/issues/11277

Workaround from the comment: reverting to v0.7.2 lua syntax:

curl -sS https://raw.githubusercontent.com/neovim/neovim/v0.7.2/runtime/syntax/lua.vim > $VIMRUNTIME/syntax/lua.vim

I'm pretty sure it is because (n)vim uses vimscript syntax highlighting for lua heredocs. Check this out for workarounds: https://www.reddit.com/r/neovim/comments/j3xmf3/how_can_i_highlight_lua_code_in_a_usual_vim_file/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM