Sublime Forum

Wrap with abbreviation for ERB

#1

I love Emmet’s Wrap With Abbreviation (docs).

It lets me quickly create a html list from a regular list

start:

foo
bar
baz

command:

ul>li*  

result:

<ul>
  <li>foo</li>
  <li>bar</li>
  <li>baz</li>
</ul>

I really want to be able to do the same with with ERB tags

start:

link_to micropost.user.name, micropost.user
micropost.content
time_ago_in_words(micropost.created_at)

command:

???

end:

<%= link_to micropost.user.name, micropost.user %>
<%= micropost.content %>
<%= time_ago_in_words(micropost.created_at) %>

Is this possible?

Currently I’m using erb snippets and it’s awful to have to focus on my erb line by line.

I want to focus on just my ruby all the way, then focus on the erb tags, then focus on the html tags, then focus on the html classes/ids.

I found a great snippet that lets me wrap individual lines, however if If I try it with multiple lines I get:

start:

user.cats
user.dogs

command:

<snippet>
  <content><![CDATA[
<%= ${0:$TM_SELECTED_TEXT} %>
]]></content>
  <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
  <!-- <tabTrigger>hello</tabTrigger> -->
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <!-- <scope>source.erb</scope> -->
    <description>ERB: Wrap with =</description>
</snippet>

result:

<%= user.cats
user.dogs %>

But I’d like to get

<%= user.cat %>
<%= user.dogs %>

Would love some help :smile:

1 Like

#2

One way to get this to do what you want is to split your selection into multiple lines using Selection > Split Into Lines (Ctrl+Shift+L on Windows/Linux). Once you do that when you invoke the snippet it will operate on each selection individually.

1 Like

#3

I wish I could like this more times :smiley: you rock @OdatNurd!

Thank you, thank you

Just wondering, is it possible to merge the multiple cursors back into one and maintain selection?

Also, what do you use to make your gifs?

0 Likes

#4

I don’t think there’s a direct way to do it, but I have this vague recollection that I’ve seen a plugin that provides that kind of functionality. I’m blanking on a name and not having any luck finding it in PackageControl, though. I think it would be fairly simple to create a plugin that did it, as long as all of the selections were adjacent to each other, though.

For that one I used LiceCap. I’ve got a few different things that do that installed but that’s my go-to for quick jobs.

1 Like

#5

1 Like