Skip to content

Commands

Published by x_ror

Run any command from the Command Palette (Ctrl+Shift+P, or Cmd+Shift+P on macOS); they are listed under Ruby Templates.

Command Keys (Windows, Linux) Keys (macOS) What it does
Toggle ERB Tag / Haml Prefix / Slim Line Ctrl+Alt+E Cmd+Alt+E <% %> → <%= %> → <%# %>, and the same for - / = / comment in Haml and Slim
Wrap Selection in ERB / Slim Output Ctrl+Alt+W Cmd+Alt+W foo → <%= foo %>, = foo or #{foo}
Extract Selection to Partial none none Moves the selection into _name.html.erb (or Haml, Slim) and leaves a render
Switch to Related File none none View ↔ other formats ↔ controller action; ViewComponent class ↔ template ↔ preview
Re-indent Haml (Document or Selection) none none Re-indents a Haml document or the selection

In ERB, Ctrl+/ (Cmd+/ on macOS) is bound to the extension’s line comment toggle, which follows the file’s host language; see Comment toggling.

Toggle ERB Tag cycles the tag under the cursor:

<% user.name %>
<%= user.name %>
<%# user.name %>

In Haml it cycles the line prefix (-, =, -#), and in Slim the line indicator (-, =, ==, /).

Extract Selection to Partial works the same in ERB, Haml and Slim: the new partial and the render call are one edit, so a single undo reverts both. The name must be a Ruby identifier, optionally prefixed by folders (shared/card), and the render path is qualified (render "users/card"). An existing partial is overwritten only after you confirm.

Command Keys (Windows, Linux) Keys (macOS) What it does
Preview Rendered HTML Ctrl+Alt+P Cmd+Alt+P Renders the template in a side panel, optionally through your Rails app
Show Compiled Ruby Source none none The Ruby the template engine generates, for debugging

The preview is controlled by three settings:

  • rubyTemplates.preview.useRails renders through the app’s bin/rails runner when the file is inside a Rails app, so helpers, routes and partials work. It boots the app on every refresh and gives up after 60 seconds.
  • rubyTemplates.preview.useBundler prefixes render commands with bundle exec when a Gemfile exists in the workspace.
  • rubyTemplates.preview.refreshOnSave re-renders the preview whenever the template is saved.

rubyTemplates.slim.compileForRails makes Show Compiled Ruby Source for Slim run slimrb --rails, as Rails compiles it.

Command What it does
Convert ERB/HTML → Haml Converts the current file to Haml
Convert Haml/Slim → ERB Converts the current file to ERB
Convert ERB/Haml → Slim Converts the current file to Slim

Restart Language Server restarts the language server. Its log is the Ruby Templates channel in the Output panel.

Preview and the converters call Ruby gems, installed only if you use them:

Gem Used for Setting for the executable
slim Rendering Slim rubyTemplates.commands.slimrb
haml Rendering Haml rubyTemplates.commands.haml
erubi Previewing and compiling ERB through Erubi (stdlib ERB without it) rubyTemplates.commands.ruby
haml_to_erb Haml → ERB rubyTemplates.commands.ruby
html2haml ERB → Haml rubyTemplates.commands.html2haml
html2slim ERB → Slim rubyTemplates.commands.erb2slim
haml2slim Haml → Slim rubyTemplates.commands.haml2slim

Everything else works without Ruby.