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

4

12

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.

Scroggins answered 24/2, 2012 at 11:31 Comment(1)
ST2 already auto-indents; where isn't it auto-indenting?Spiraea
D
11

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.

Discoverer answered 25/2, 2012 at 0:40 Comment(1)
Thanks for this. I'm sure people can figure it out but just in case I adjusted it to use "contents": "%$0 %>" instead so you can easily type <%= without having to backspace.Hendel
T
12

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

Tricia answered 1/4, 2012 at 18:45 Comment(0)
D
11

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.

Discoverer answered 25/2, 2012 at 0:40 Comment(1)
Thanks for this. I'm sure people can figure it out but just in case I adjusted it to use "contents": "%$0 %>" instead so you can easily type <%= without having to backspace.Hendel
D
8

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 %>

Dit answered 10/5, 2014 at 23:36 Comment(0)
O
1

If you are looking for autocomplete suggest, change the auto_complete_selector in Preference like:

"auto_complete_selector": "text, source - comment",
Oppress answered 7/6, 2013 at 20:42 Comment(1)
Thank you so much for this, absolutely nothing else worked for me.Bloodhound

© 2022 - 2024 — McMap. All rights reserved.