stackjlei
stackjlei

Reputation: 10035

how do I set shortcuts on sublime text 3?

I want to be able to make <%= %> by pressing '=' and 'tab' like in Atom. I downloaded ERB snippets package but it uses other keys in order to make that shortcut. How do I change this?

Upvotes: 0

Views: 125

Answers (2)

Sebasti&#225;n Palma
Sebasti&#225;n Palma

Reputation: 33471

In Sublime isn't so simple as in Atom, they don't store in the same file, but in a folder within your User configuration as different files, to do it just go to Tools->Developer->New Snippet, and you'll see a new tab:

<snippet>
  <content><![CDATA[
Hello, ${1:this} is a ${2:snippet}.
]]></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.python</scope> -->
</snippet>

All that's between the CDATA is the body of your snippet, and is what you'll see on the editor and where you'll define the pointer position, the code block, and a "placeholder" message, try this way:

<%= ${1:your_awesome_code} %>

Those are the common erb markers, and what's inside is what you'll see when you press tab or select the snippet, the ${} is to open and close the statement, the 1 inside is a field and is telling that it'll be the first thing you'll have under the cursor, because you can assign this same way one or more fields with or without "placeholders", as you want, the : will divide it from "order" and "what you'll get", this way, when you use it you'll have:

<%= your_awesome_code %>

The whole phrase on the cursor, then you can easily erase it and keep coding (it was just an example)

Then within the <tabTrigger> tag you declare the shortcut to select the snippet, in this case will be the = character, so:

<tabTrigger>=</tabTrigger>

Now when you type = on Sublime and hit the tab key the code you defined as snippet will appear on your editor, if it's the only one setted with =, if there are two or more you'll have the opportunity to choose between any of them.

And additional you can set the scope that's to say, that snippet will only appear in files that are recognized by Sublime as the file extension of that language.

Upvotes: 1

Curiosity List
Curiosity List

Reputation: 34

Here is a cheat sheet https://www.cheatography.com/tdeyle/cheat-sheets/sublime-text-3/. Hopefully, this helps. I love Sublime, but it takes some time to learn how to use the keystrokes.

If they keystrokes aren't working at all, perhaps try to restart Sublime. Also the free version may have more limits than the purchased one just as a note.

Upvotes: 1

Related Questions