如何在 sublime text 2 中设置/使用 ruby on rails 片段和自动完成?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9430026/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I setup/use ruby on rails snippets and autocomplete in sublime text 2?
提问by LondonGuy
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.
我已经安装了一个 rails 片段包和 ryan-on-rails 包。只是对如何开始使用它们感到困惑。
I'm on max osx - snow leopard
我在 max osx 上 - 雪豹
Kind regards
亲切的问候
Update
更新
This helped me out. http://webtempest.com/sublime-text-2-how-to-create-snippets/but I still need a little practice.
这帮助了我。http://webtempest.com/sublime-text-2-how-to-create-snippets/但我仍然需要一些练习。
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?
Also would like some auto indentation.. and also complete.
我有一个包“rails”不记得我从哪里得到的,但是片段的触发正在起作用。我只想找到一个很好的命令列表,而不必去每个片段并寻找自己。我可以通过单击片段找到它,但没有办法为此创建快捷方式吗?
还想要一些自动缩进……而且还完整。
采纳答案by BoundinCode
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.
由于您是 Sublime Text 的新手,我强烈建议您查看:ST2 的非官方文档。如果包括大量入门信息以及大量可扩展性和插件开发信息。
Another great "Getting Started" guide can be found here on Nettuts+.
另一个很棒的“入门”指南可以在 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": "% "auto_complete_selector": "text, source - comment",
%>"
},
"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.
最新的测试版包括改进的自动缩进,所以如果你没有安装它,试试看。至于自动补全,Sublime Text 2 默认提供当前文档中单词的自动补全(加上你所有的代码片段/包中的补全)。但是,如果您正在寻找类似 IDE 的自动完成功能,则可以使用 SublimeCodeIntel 插件。我不愿意提及它,因为它几个月没有更新并且错误报告不断涌入。
Hope that helps.
希望有帮助。
回答by rda3000
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:
我很困惑这不是默认 Rails 包的一部分,但我发现这正是我想要的:
回答by Joshua Dance
I use ERB Snippets
我使用 ERB 片段
https://github.com/matthewrobertson/ERB-Sublime-Snippets
https://github.com/matthewrobertson/ERB-Sublime-Snippets
You can install via Sublime Package control
你可以通过 Sublime Package control 安装
Cmd+Shift+P
Cmd+ Shift+P
Go to Package Control: Install Package.
转到包控制:安装包。
Type ERB Snippets. Let it roll.
键入ERB Snippets。让它滚动。
Then you can use tab autocomplete for lots of snippets such as:
然后,您可以对许多片段使用选项卡自动完成功能,例如:
print ERB tags = pewhich auto completes to <%= %>
if block = ifwhich auto completes to <% if %>...<% end %>
打印 ERB 标签 =pe自动完成到<%= %>
if 块 =if自动完成到<% if %>...<% end %>
回答by Yongqinchuan Du
If you are looking for autocomplete suggest, change the auto_complete_selectorin Preference like:
如果您正在寻找自动完成建议,请将auto_complete_selector首选项中的更改为:

