如果我打开第二个选项卡,Vim 中的 CSS 突出显示会中断
我一直在从头开始重写我的简历(我认为这是开始新的一年的好方法),并且我正在将其作为网页进行。当然,我想要所有的 HTML、CSS 和Javascript 在一个文件中,因此它是可移植的。
在 Vim 中工作时,我有 CSS、HTML 和 HTML。文档的 Javascript 部分在单独的选项卡中打开。但一旦我打开第二个选项卡,CSS 的语法突出显示就会关闭。 HTML 和 Javascript 继续正确突出显示。
无论如何,我都不是 Vim 专家,所以如果这是一个太基础的问题,我深表歉意,但我找不到任何解决此问题的文档(或 Stackoverflow 上的现有帖子)。
预先感谢您的任何见解。
I've been re-writing my resume from scratch (good way to start the new year, I think,) and I'm doing it as a webpage. Naturally I want all the HTML, CSS & Javascript in one file, so it'll be portable.
While working on it in Vim, I have the CSS, HTML, & Javascript sections of the document open in separate tabs. But as soon as I open a second tab, the syntax highlighting for the CSS turns off. The HTML and Javascript continue to be highlighted properly.
I'm not a Vim expert by any means, so I apologize if this is too basic a question, but I couldn't find any documentation (or existing posts on Stackoverflow) that address this issue.
Thanks in advance for any insight.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为 vim 并不是从文件的“顶部”开始查找突出显示,而是从当前屏幕视图的几百行开始查找,因此有时您可以通过滚动来使突出显示起作用周围一点。
如果这有效,您可以调整语法突出显示控件,这样您就不必浪费时间滚动;有关完整详细信息,请参阅
:help syn-sync
。有几个选项:强制
vim
每次都从文件的开头开始识别语法。这可能会导致大文件出现严重的性能问题,但这也可能表明您的源可以更好地拆分。增加解析的行数。这减少了语法识别错误的可能性,而不必每次都从头开始重新解析整个文件。
选择一个足够大的数字,几乎可以一直工作,而不会造成明显的性能损失。这可能是最好的方法,即使
500
行在过去十年的大多数计算机上也应该没问题。如果您正在编辑 C 风格代码,
vim
可以使用 C 风格注释轻松重新同步。 (注意,不是// newfangled
变体,而是/* 原始样式 */
。)可能不是 HTML、CSS、JavaScript 的最佳选择,但也许您的代码使更可行:第四种方法使用“同步模式”,类似于C风格的注释,但更适用于其他环境。它有足够多的额外复杂性,我认为在这里描述它不值得付出努力 -
:help syn-sync-fourth
包含了好奇的所有细节。这些配置选项中的任何一个都可以添加到您的
~/.vimrc
文件中:您可以根据您正在编辑的文件类型来更改行为。向文件添加行时,只需省略前导
:
即可。使用autocmd
为如下类型定义它:Because
vim
doesn't start looking for highlighting at the "top" of the file, but rather a few hundred lines up from the current on-screen view, you can sometimes get the highlighting to work by scrolling around a little.If this works, you can tweak the syntax highlighting controls so that you don't have to waste your time scrolling around; for full details, see
:help syn-sync
. There's several options:Forcing
vim
to start recognizing syntax from the very start of the file every time. This might lead to significant performance problems on huge files but that might also be an indication that your source could be better split apart.Increase the number of lines that are parsed. This reduces the chances of bad syntax recognition without necessarily incurring the expense of reparsing the entire file from the start each time.
Pick a number that is large enough to work almost all the time without significant performance penalties. This is probably the best approach to take, even
500
lines ought to be alright on most computers from the last decade.If you're editing C-style code,
vim
can easily resynchronize using C-style comments. (Note, not the// newfangled
variety but/* the original style */
.) Probably not the best choice for HTML, CSS, JavaScript, but perhaps your code makes it more feasible:The fourth method uses "sync patterns", similar to the C-style comments, but more applicable to other environments. It has enough extra complications that I don't think describing it here is worth the effort --
:help syn-sync-fourth
has all the details for the curious.Any of these configuration options can be added to your
~/.vimrc
file:You can change the behavior based on what kind of files you're editing. Just leave off the leading
:
when adding lines to the file. Useautocmd
to define it for types like this:这些可能与提供答案相关
您使用的是哪个版本的 vim?我假设您使用的是 Vim 7.3(如果没有,您应该 - 大多数 linux distors 都有它,并且有一个 exe适用于 Windows 和 MacVim 适用于 osx)。可能是您的安装太旧或损坏。
有任何插件吗? 一个简单的检查是暂时删除所有插件,重新启动 vim 并查看是否仍然发生这种情况。
你的.vimrc中有什么特别的
.vimrc
?如果你自己定制的话可能不会有太多惊喜,但如果你是从别人那里借来的,您可以对插件文件夹(空或裸最小文件)执行相同的操作。希望这会有所帮助 - 祝你好运!
These may become relevant to provide an answer
what version of vim are you using? I'm assuming you're using Vim 7.3 (if not, you should - most linux distors have it, and there's an exe for Windows and MacVim for osx). It could be that your installation is old or broken.
Any plugins? A simple check will be to temporarily remove all your plugins, restart vim and see if this still happens.
Anything special in your
.vimrc
? If you customized it yourself then there are probably not too many surprises, but if you borrowed from someone else, you can do the same thing you did with the plugins folder (empty or bare-minimum file).Hope this helps - good luck!