Run any command from the Command Palette (Ctrl+Shift+P, or Cmd+Shift+P on macOS); they are listed under Alder.
Editing commands
Section titled “Editing commands”| Command | Keys (Windows, Linux) | Keys (macOS) | What it does |
|---|---|---|---|
| Toggle ERB Tag / Haml Prefix / Slim Line / Pug Line | Ctrl+Alt+E | Cmd+Alt+E | <% %> → <%= %> → <%# %>, and the same for - / = / comment in Haml, Slim and Pug |
| Wrap Selection in ERB / Slim / Pug 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; in Pug, a file and an include |
| Switch to Related File | none | none | View ↔ other formats ↔ controller action; ViewComponent class ↔ template ↔ preview |
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 a tag
Section titled “Toggle a tag”Toggle ERB Tag cycles the tag under the cursor:
<% user.name %>
<%= user.name %>
<%# user.name %>
In Haml it cycles the line prefix (-, =, -#), in Slim the line indicator (-, =, ==, /), and in Pug the line’s marker (-, =, !=, //-); see Pug.
Extract a partial
Section titled “Extract a partial”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.
The three editing commands work on Pug (.pug, .jade, .jst.pug) as they do on Slim, kept to what Pug compiles:
- Toggle Pug Line cycles
-→=→!=→//-→-on each selected line. The step to=turns code that runs into code whose value is written to the page:- x++becomes= x++, which still incrementsxand now also writes its value. Code that can’t be a JavaScript expression (- var x = 1,- if (a) {) goes from-straight to//-, since Pug refuses it after=. A//-comment goes back to-only when it reads as code, an expression or a statement such asif (a)orvar x = 1; a comment in words (//- TODO fix this) has nothing to toggle to and stays. A line with lines nested under it is left alone (Pug refuses a block under=, and a//-comment’s nested lines are its text), and so are lines insidescript., filters, comments,-code blocks and attribute lists over several lines. - Wrap Selection in Pug Output turns a whole line into
= linewhen it has nothing nested and reads as a JavaScript expression (items.length > 0,user.name + "!"), and a selection in text (after a tag, after|, insidep.or under a//comment, whose nested lines Pug outputs with their#{}) into#{selection}. A line Pug reads as a tag is left alone, even when it would be an expression too:user.nameis the taguserwith the classname, andt('x')the tagtwith an attribute. A selection in a tag’s name or attributes, inside another#{}or!{}or in the tag of a#[], on a keyword line, in code, an attribute list, a//-comment or a comment’s own line, or one that can’t be an expression (Hello world) is left as it is, with a message. An empty selection inserts#{}to type in. Whether text is a JavaScript expression is a guess, as no JavaScript parser runs: brackets and quotes must close, and two words may not stand side by side. - Extract Selection to Partial moves the selected lines, with every line nested under them (so
script.keeps its text) and the rest of an attribute list they open, into a new file in the template’s folder (row, orusers/rowfor a subfolder), with the template’s extensions:row.jst.pugfromlist.jst.pug,row.pugfromlist.pug. The lines move to the left edge, keeping their indentation relative to each other, and anincludereplaces them, with the path Pug reads:include row.jst.pug, orinclude rowfor a.pugfile, since Pug adds.pugto a path without an extension. There are no_names or locals: an included file shares the template’s variables. It refuses a selection that starts inside a text block, inside an attribute list or deeper than it ends, holdsextends, holds a mixin’sblockwithout itsmixin, or would part anif,caseoreachfrom itselse,whenordefault.
Preview and compiled source
Section titled “Preview and compiled source”| 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:
alder.preview.useRailsrenders through the app’sbin/rails runnerwhen 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.alder.preview.useBundlerprefixes render commands withbundle execwhen a Gemfile exists in the workspace.alder.preview.refreshOnSavere-renders the preview whenever the template is saved.
alder.slim.compileForRails makes Show Compiled Ruby Source for Slim run slimrb --rails, as Rails compiles it.
Converters
Section titled “Converters”| 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 |
Language server
Section titled “Language server”Restart Language Server restarts the language server. Its log is the Alder channel in the Output panel.
Ruby gems
Section titled “Ruby gems”Preview and the converters call Ruby gems, installed only if you use them:
| Gem | Used for | Setting for the executable |
|---|---|---|
slim |
Rendering Slim | alder.commands.slimrb |
haml |
Rendering Haml | alder.commands.haml |
erubi |
Previewing and compiling ERB through Erubi (stdlib ERB without it) | alder.commands.ruby |
haml_to_erb |
Haml → ERB | alder.commands.ruby |
html2haml |
ERB → Haml | alder.commands.html2haml |
html2slim |
ERB → Slim | alder.commands.erb2slim |
haml2slim |
Haml → Slim | alder.commands.haml2slim |
Everything else works without Ruby.