为什么我只能在 VIM 的某些项目中获得 RSpec 的语法高亮显示?

发布于 2024-12-26 12:21:34 字数 545 浏览 1 评论 0原文

在开始一个新项目后不久,我意识到我的 RSpec 文件没有得到正确的语法突出显示。

起初我认为这只是因为我的项目特定的 .vimrc,它是通过 set exrc 加载的。但即使我删除了它,也没有帮助。

我还认为问题出在规范文件本身,它没有被识别为 RSpec,所以我从另一个项目中获取了一个文件,将其复制过来,但它仍然没有被正确突出显示。

语法突出显示

这是在两个不同位置打开的同一个文件。左边的是原始项目,它确实突出显示,右边的是复制的版本。

该项目中的所有 RSpec 文件都会发生同样的情况,但它似乎在其他地方都适用。

这是我的 ~/.vimrc,但我不认为这是任何相关性,因为我以前从未遇到过这个问题,只在这个特定的项目中遇到过。

Soon after starting a new project I realized, that I'm not getting the correct syntax highlighting for my RSpec files.

At first I thought this is just because of my project specific .vimrc, which are loaded via set exrc. But even after I deleted it, it didn't help.

I also thought that the problem is in the spec file itself, that it doesn't get recognized as RSpec, so I took a file from another project, copied it over, and it still isn't getting properly highlighted.

syntax highlighting

This is the same file opened in two different places. The one on the left is in the original project, where it does get highlighting, and the one on the right is the copied version.

The same thing happens for all the RSpec files in that one project, but it seems to work everywhere else.

Here is my ~/.vimrc, but I don't think that's of any relevance, because I never had this issue before, only in this specific project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挖个坑埋了你 2025-01-02 12:21:34

你使用的是 janus,所以你已经安装了rails.vim。正如您在此处看到的,该插件定义了适合您的语法方法,这就是为什么您仅在 Rails 项目中启用 RSpec 语法的原因。

如果您想在每个规范文件中启用该语法,您可以将以下内容添加到您的 vimrc 中:

autocmd BufRead *_spec.rb syn keyword rubyRspec describe context it specify it_should_behave_like before after setup subject its shared_examples_for shared_context let
highlight def link rubyRspec Function

You're using janus so you have rails.vim installed. As you can see here, that plugin defines the syntax methods for you and that's the reason why you have the RSpec syntax enabled only in rails projects.

If you want to enable that syntaxt in each spec file you can add the following to your vimrc:

autocmd BufRead *_spec.rb syn keyword rubyRspec describe context it specify it_should_behave_like before after setup subject its shared_examples_for shared_context let
highlight def link rubyRspec Function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文