Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get syntax highlighting for RSpec only in some projects in VIM?

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.

like image 227
Jakub Arnold Avatar asked Jan 18 '23 19:01

Jakub Arnold


1 Answers

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
like image 166
lucapette Avatar answered Feb 11 '23 19:02

lucapette