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

会有一股神秘感。 提交于 2019-12-02 17:43:54

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.

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

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

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

"auto_complete_selector": "text, source - comment",
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!