Search code examples
ruby-on-railsruby-on-rails-3ruby-on-rails-3.1code-snippetssublimetext

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.


Solution

  • 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.