vim 中的 Javascript 语法高亮显示
还有其他人发现 VIM 的 Javascript 语法突出显示效果不佳吗? 我发现有时我需要滚动才能调整语法突出显示,因为有时它会神秘地删除所有突出显示。
有没有任何解决方法或方法来解决这个问题? 我使用的是 vim 7.1。
Has anyone else found VIM's syntax highlighting of Javascript sub-optimal? I'm finding that sometimes I need to scroll around in order to get the syntax highlighting adjusted, as sometimes it mysteriously drops all highlighting.
Are there any work-arounds or ways to fix this? I'm using vim 7.1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可能想尝试这个改进的 Javascript 语法荧光笔,而不是那个与 VIMRUNTIME 一起提供。
You might like to try this improved Javascript syntax highlighter rather than the one that ships with VIMRUNTIME.
嗯,我修改了 赵毅的 Javascript 语法,并添加了 Ajax 关键字支持,还突出显示了 DOM方法及其他。
就是这样,它远非完美,因为我对 Vim 还很陌生,但到目前为止它对我有用。 我的 Javascript 语法。 如果您可以修复、添加功能,请这样做。
更新:
我忘记了这些语法突出显示仅在您将它们包含在您自己的颜色方案中时才会显示,就像我在我的Nazca
颜色方案中所做的那样。 我将测试是否可以将这些行添加到修改后的语法文件中。遵循 github,因为不再需要修改您当前的颜色方案。
Well, I've modified Yi Zhao's Javascript Syntax, and added Ajax Keywords support, also highlight DOM Methods and others.
Here it is, it is far from being perfect as I'm still new to Vim, but so far it has work for me. My Javascript Syntax. If you can fix, add features, please do.
UPDATE:
I forgot these syntax highlights are only shown if you included them in your own colorscheme, as I did in myNazca
colorscheme. I'll test if I could add these line into my modified syntax file.Follow the new version of the javascript syntax file in github, for it is no longer required to modify your current colorscheme.
这是一篇非常老的帖子,但我也遇到了同样的事情:有时,当查看
.html
文件中的 javascript 部分时,语法高亮会停止工作。 正如OP提到的,一个快速的解决方法是向上滚动,然后神奇地事情会再次开始突出显示。今天我找到了根本问题和一个很好的解决方案。 在 Vim 中,语法突出显示使用上下文来导出正确的突出显示,其中上下文由前面的行定义。 可以通过发出
:syntaxsync minlines=200
来指定使用当前行之前的行数。 在这种情况下,它将使用最多 200 行之前的行作为上下文。 通过运行:syntaxsync fromstart
可以使用整个文件(对于长文件来说可能会很慢)。一旦发现这一点,我将这一行添加到我的
.vimrc
中:通过这样做,
.html
文件将使用整个文件作为上下文。 因此,无论 JS 部分有多长,javascript 部分都将始终正确突出显示。 希望这对其他人有帮助!This is a really old post, but I was experiencing the same thing: sometimes syntax highlight would just stop working when looking at the javascript section in an
.html
file. As the OP mentions, a quick workaround was to scroll up and then magically things would start highlighting again.Today I found the underlying problem and a good solution. In Vim, syntax highlighting uses a context to derive the correct highlight, where context is defined by the previous lines. It is possible to specify how many lines before the current line are used by issuing
:syntax sync minlines=200
. In this case, it will use up to 200 previous lines as context. It is possible to use the whole file (which can be slow for long files) by running:syntax sync fromstart
.Once I found that, I added this line to my
.vimrc
:By doing so,
.html
files will use the whole file as context. Thus, the javascript section will always by highlighted properly, regardless of how long the JS section is. Hope this helps someone else out there!为了快速而肮脏的修复,有时我只是上下滚动并重新调整突出显示。 Ctrl+L 屏幕重绘也可以修复此问题。
For a quick and dirty fix, sometimes I just scroll up and down and the highlighting readjusts. Ctrl+L for a screen redraw can also fix it.
语法着色同步可能需要调整。 我发现在某些情况下我需要改变它。
语法同步(“:help syn-sync”)控制 vim 如何跟踪和刷新其对着色代码的解析,以便它可以开始在文件中的任何位置进行绘制。
默认值并不总是适合我,所以有时我发现自己发出
建议阅读下面的文档
,或者只是检查
并找到有关同步的部分。
在四个可用的基本选项中做出明智的决定。
我维护到功能键的映射,以在“fromstart”和“ccomment”模式之间切换,以及仅清除同步设置。
Syntax coloring synchronization probably needs adjustment. I've found in certain contexts that I need to change it.
Syntax synchronization (":help syn-sync") controls how vim keeps track of and refreshes its parse of the code for coloring, so that it can start drawing anywhere in the file.
The defaults don't always work for me, so sometimes I find myself issuing
I suggest reading through the documentation under
or just check
and find the section on synchronization.
to make an informed decision among the four available basic options.
I maintain mappings to function keys to switch between "fromstart" and "ccomment" modes and for just clearing the sync settings.