Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim html.erb snippets?? snipMate Need a vim tip

When I'm in an html.erb file, I get no snipMate snippets.

I would like both HTML and Ruby, or just HTML would be fine, How would I do this?

Would I need to write a set of snippets?

If so, is there a way of pulling in existing snippets without copying them?

Is there a way of telling vim to go into html mode when it sees .html erb?

like image 273
Daniel Upton Avatar asked Jan 11 '11 14:01

Daniel Upton


2 Answers

You can use an autocmd to set the filetype to html when opening a ".html.erb" file. This could have unwanted side effects for plugins that work for ".erb" files.

autocmd BufNewFile,BufRead *.html.erb set filetype=html

You can also load more than one set of snippets by using a dotted filetype:

autocmd BufNewFile,BufRead *.html.erb set filetype=html.eruby

See :help snippet-syntax in the snipMate help for more info.

like image 97
Randy Morris Avatar answered Oct 19 '22 14:10

Randy Morris


Snippets are stored in directory called snippets somewhere in your ~/.vim folder.

If you look there, there is usually one file per filetype, there is a c.snippets, a ruby.snippets, so it seems what you have to do is to create an erb.snippets there with what you want.

Eventually you could copy the content of ruby.snippets and html.snippets into your new erb.snippets.

Alternatively you can search on github, some people have posted their own erb.snippets configuration. For example, there is a nice collection there : https://github.com/scrooloose/snipmate-snippets

The best thing would to try first to open a snippet file and look at the syntax, it is pretty easy to create your own snippet depending on what you use the most.

like image 12
Xavier T. Avatar answered Oct 19 '22 13:10

Xavier T.