can't get ultisnips working with rspec

Asked by Aldric Giacomoni

RSpec files in ruby are named thus : *_spec.rb

I use pathogen, and did a git clone in the bundle directory.
I tried with a simple ultisnip snippet for Ruby - 'def<tab>'. And it worked.
I created a file called 'rspec.snippets' in the UltiSnips directory, along with all the other files from the repository: html, htmldjango, etc.

The file begins with :

extends ruby

The file ends with:

# vim:ft=snippets:

And inside there's some snippets like:

snippet subj "subject"
subject { $1 }
endsnippet

So... When I open a file like something_spec.rb ... And I try to do the 'def' snippet... It works.
But when I try the 'subj' snippet.. It doesn't.

What am I doing wrong or not doing?

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
SirVer
Solved:
Last query:
Last reply:
Revision history for this message
Best SirVer (sirver) said :
#1

Check your filetype: set ft
you want to set it to

:set ft=rspec

or more likely:

:set ft=ruby.rspec

you migth want to drop the extends line then.

Read up on :help filetypes , especially the dotted file type syntax.

Revision history for this message
Aldric Giacomoni (trevoke) said :
#2

Okay, so there's some magic happening between the name of the snippet file and the filetype to which it is applied -- so I basically have two options:

- change the filetype of *_spec.rb to a special "rspec" format and possibly break everything
- just call the file ruby_rspec.snippets and accept that the rspec snippets will work in other Ruby files.

I went with option two.

Revision history for this message
Aldric Giacomoni (trevoke) said :
#3

Thanks SirVer, that solved my question.

Revision history for this message
SirVer (sirver) said :
#4

No, there is no magic. Ultisnips just uses Vims filetype. Vim allows to have more than one filetype enabled at all times. You can safely add a new filetype to Ruby files which are also 'spec' (I have no idea what that is, as I do not speak ruby). The filetype will be
:set ft=ruby.spec
which means ruby AND spec.

Whatever breaks with this setting does not adhere to Vims rules and is rightfully broken.

Revision history for this message
Aldric Giacomoni (trevoke) said :
#5

Thanks for the explanation. This was very helpful.