Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I setup/use ruby on rails snippets and autocomplete in sublime text 2?

I would appreciate if someone could direct me to a website that shows how to do this.. Can't seem to find anything decent enough via google.

This will be the first time I'm doing this kind of thing with a text editor.. It has got to the stage where typing out things like <%= %> is getting old and slow.

I've got a rails snippet package and also ryan-on-rails package installed. Just confused with how to start using them.

I'm on max osx - snow leopard

Kind regards

Update

This helped me out. http://webtempest.com/sublime-text-2-how-to-create-snippets/ but I still need a little practice.

  1. I have a package "rails" can't remember where I got it but the triggering of snippets is working. I'd just like to find a nice list of the commands rather than have to go to each snippet and look for myself. I can find the by clicking on snippets but isn't there a way I can create a shortcut for that?

  2. Also would like some auto indentation.. and also complete.

like image 370
LondonGuy Avatar asked Feb 24 '12 11:02

LondonGuy


3 Answers

I'm puzzled that this isn't part of the default Rails package, but I found this to be just what I was looking for:

https://github.com/eddorre/SublimeERB

like image 170
rda3000 Avatar answered Nov 15 '22 04:11

rda3000


Since you're new to Sublime Text, I highly recommend you check out: ST2's Unofficial Documentation. If includes a ton of getting started info plus tons of info for extendibility and plugin development.

Another great "Getting Started" guide can be found here on Nettuts+.

If you're looking a list of your snippets and their associated shortcuts, go to "Tools > Snippets..." from your menu.

To expand <% into <%| %> (where | is the cursor), add the following you to your User-keybindings (Preferences > Keybindings - User):

 {
   "args": {
     "contents": "% $0 %>"
   }, 
   "command": "insert_snippet", 
   "context": [
     {
       "key": "selector", 
       "match_all": true, 
       "operand": "source.ruby", 
       "operator": "equal"
     },
     { "key": "preceding_text", "operator": "regex_match", "operand": ".*<", "match_all": true }
   ],
   "keys": [
     "%"
     ]
   }

The latest beta includes improved auto-indentation, so if you don't have that installed, try that out. As for autocompletion, Sublime Text 2 by default offers autocompletion of words in the current document (plus all of your snippets/completions from packages). However, if you're looking for IDE-like autocompletion, there is the SublimeCodeIntel plugin. I am reluctant to mention it because it has not been updated in months and the bug reports keep flowing in.

Hope that helps.

like image 39
Liam Cain Avatar answered Nov 15 '22 05:11

Liam Cain


I use ERB Snippets

https://github.com/matthewrobertson/ERB-Sublime-Snippets

You can install via Sublime Package control

Cmd+Shift+P

Go to Package Control: Install Package.

Type ERB Snippets. Let it roll.

Then you can use tab autocomplete for lots of snippets such as:

print ERB tags = pe which auto completes to <%= %>
if block = if which auto completes to <% if %>...<% end %>

like image 8
Joshua Dance Avatar answered Nov 15 '22 03:11

Joshua Dance