Vim为什么用红色突出显示我所有的JSON注释?

ARM*_*TAV 0 vim vim-syntax-highlighting neovim

我在JSON文件中自动生成了一些注释,但不幸的是,似乎vim无法识别它们只是注释。

在此处输入图片说明

它们都是红色的-我的哪个插件正在执行此操作?

我真的不想关闭所有语法高亮显示,也不想每次遇到红色高亮显示时手动清除错误。

" Enable syntax highlighting
syntax enable

" PLUGINS
call plug#begin('~/.vim/plugged')

"   deoplete - code completion
if has('nvim')
"      Add in a syntax file for deoplete typescripe, then add deoplete
    Plug 'HerringtonDarkholme/yats.vim'
    Plug 'mhartington/nvim-typescript', {'do': './install.sh'}
    Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
    Plug 'Shougo/deoplete.nvim'
    Plug 'roxma/nvim-yarp'
    Plug 'roxma/vim-hug-neovim-rpc'
    Plug 'ternjs/tern_for_vim', { 'do': 'npm install' }
endif

"   fzf - fuzzy find
Plug 'junegunn/fzf', { 'dir': '~/.vim/installed/fzf' }

"   lightline - a nice looking bottom bar
Plug 'itchyny/lightline.vim'
"       also get rid of the useless -- INSERT -- since we have a nice bar
set noshowmode

"   nerdtree - a little tree file browser 
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
"       map it to control-O
map <C-o> :NERDTreeToggle<CR>

"   gitgutter - adds some git context to the left side bar
Plug 'airblade/vim-gitgutter'
set updatetime=100

"   ale - asynchronous linting engine, highlights stuff
Plug 'w0rp/ale'

"   deoplete-ternjs - adds javascript to deoplete
Plug 'carlitux/deoplete-ternjs'
"   tern_for_vim - adds in the tern 'engine' or whatever to vim
Plug 'ternjs/tern_for_vim', { 'do': 'npm install && npm install -g tern' }

"   vimproc - async execution for things
Plug 'Shougo/vimproc.vim', { 'do': 'make' }
"   tsuquyomi - unpronouncable client for TSServer for completion and more
Plug 'Quramy/tsuquyomi', { 'do': 'npm install -g typescript' }

call plug#end()

" CONFIGURE - some of our plugins need configurations so add that in

let g:deoplete#enable_at_startup = 1
let g:deoplete#enable_ignore_case = 1
let g:deoplete#enable_smart_case = 1
let g:deoplete#enable_camel_case = 1
let g:deoplete#enable_refresh_always = 1
let g:deoplete#max_abbr_width = 0
let g:deoplete#max_menu_width = 0
let g:deoplete#omni#input_patterns = get(g:,'deoplete#omni#input_patterns',{})

let g:tern_request_timeout = 1
let g:tern_request_timeout = 6000
let g:tern#command = ["tern"]
let g:tern#arguments = ["--persistent"]
let g:deoplete#sources#tss#javascript_support = 1
let g:tsuquyomi_javascript_support = 1
let g:tsuquyomi_auto_open = 1
let g:tsuquyomi_disable_quickfix = 1
Run Code Online (Sandbox Code Playgroud)

Ali*_*Ali 9

这为我解决了这个问题:

autocmd FileType json syntax match Comment +\/\/.\+$+
Run Code Online (Sandbox Code Playgroud)

不知道我从哪里得到它。

编辑:

请注意,要使此功能起作用,您必须让 vim 通过 来处理文件类型检测filetype on。把它放在上面的某个地方autocmd ...


Jim*_*sin 8

我发现有一个注释 json 的插件可以解决这个问题:jsonc。你应该检查一下。


pad*_*win 6

作为@Michail提到,JSON语法确实支持的意见,这样的Vim其标记为错误。

  • @TanjimHossain 你的观点是?每个人都知道 JSON-with-comments 不是 JSON,但这并不能阻止人们(微软是最严重的罪犯)创建生成和使用 JSON-with-comments 的工具。这使得其他人需要可以理解 JSON-with-comments 的语法突出显示(并且不仅仅是 JSON-with-errors,因为其他语法错误(例如尾随逗号)仍然是错误)。 (7认同)
  • 不过,有不计其数的工具使用带注释的 JSON。 (2认同)