Search code examples
rubymine

Rubymine: How to generate <% %> in .erb file with shortcut?


I know ctrl+shift+. could generate <%= %>. But how can I generate <% %>?

And Can I generate <% if %> and <% end %> in pair?


Solution

  • (Assuming Mac here) There is no default keymap for that. It's not ideal, but I have created live templates for those. So for example, you could create a live template that looks like this:

    <% if $END$ %>
    
    <% end %>
    

    And make it applicable in ERB. Then while editing your ERB you could CMD+j which will bring up live template autocomplete. Then just type the first few letters of whatever you named the live template ("if" for example) and it will drop the code in there for you and place the cursor wherever $END$ is defined.

    It's a few more keystrokes, but it works. For more info on creating live templates in RubyMine check out the docs