Gvim 无法正确突出显示语法,如何修复?
我有一个 HTML 文件,其中包含 HTML 和 JavaScript。当我折叠一些代码片段时,语法突出显示效果不佳。截图如下:
Line79 函数 setColor(color) 未正确突出显示。有什么办法可以解决吗?
顺便说一句,我在 Windows 7 中使用 GVIM 7.2。
谢谢!
I have a HTML file which contains both HTML and JavaScript. When I folded some code snippets, the syntax highlight didn't work well. Screenshot as following:
Line79 function setColor(color) is not correctly highlighted. Is there any way to fix it?
BTW, I am using GVIM 7.2 in windows 7.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当 Vim 打开 html 文件时,它会在整个文件中应用 html 突出显示。当 html 文件中有单独的语言时,您需要定义语法区域,让 Vim 知道文件的某些部分将以与文件扩展名标识的语言不同的方式突出显示。我在此处回答一个 SO 问题时描述了如何执行此操作: 在 VIM 中,如何在同一个文件中混合 jinja 和 javascript 的语法/标识规则?
另请参阅以下位置的文档:
:h syn-include
。缩进类似。也就是说,Vim 会将 html 缩进规则应用于文件中的所有内容,除非您告诉它以不同的方式缩进 Javascript 区域。
注意:也许由于嵌入 javascript 的 html 非常常见,因此 html 语法文件可能默认支持嵌入 javascript。下面链接的提示建议使用
:set filetype htmlm4
来获得适当的突出显示,尽管评论者说这不是必需的:http://vim.wikia.com/wiki/Syntax_highlighting_for_HTML_with_embedded_Javascript
When Vim opens an html file it applies html highlighting throughout the file. When you have a separate language in the html file you need to define syntax regions to let Vim know that parts of the file are to be highlighted differently from the language identified by the file extension. I described how to do this in an answer to an SO question here: In VIM, how can I mix syntax/ident rules of both jinja and javascript in the same file?
Also review the docs at
:h syn-include
.Indenting is similar. That is, Vim will apply html indenting rules to everything within the file unless you tell it to indent the Javascript region differently.
NOTE: Maybe since html with embedded javascript is so common the html syntax files may by default support embedded javascript. The tip linked below suggests using
:set filetype htmlm4
to get proper highlighting, although a commenter says that should not be necessary:http://vim.wikia.com/wiki/Syntax_highlighting_for_HTML_with_embedded_Javascript
:synsync fromstart
(另请参阅
help syn-sync-first
):syn sync fromstart
(See also
help syn-sync-first
)可能是你的 mapInit() 函数中有一行的长度超过了 vim 的 'synmaxcol' 设置。请注意,第 77 行(右大括号)的突出显示也不正确。
来自vim的帮助:
It may be that you have a line in the mapInit() function whose length exceeds vim's 'synmaxcol' setting Notice the highlighting is incorrect on line 77 too (the closing brace).
From vim's help: