how do I set shortcuts on sublime text 3? - sublimetext3

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?

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.

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.

Related

Force sublime to place space after if/for

Visual studio can place space between if and (:
if you write if( it will autocorrect it to if ( - with space. Same with for and while
Can you do such thing in sublime?
You can install HTML-CSS-JS Prettify package.
Go to Preferences > Package Settings > HTML-CSS-JS Prettify > Prettify Preferences - Default
Then search for space_before... options to adapt to what you need.
In your case, probably you want this:
// Should the space before conditional statement be added, "if(true)" vs "if (true)"
"space_before_conditional": true,
Ctrl + Shift + H is the default key binding to run these customized settings.
This is my solution for this in ST3.
From the menu, choose Tools -> Developer -> New Snippet...
It will generate a file like this (delete comments for simplicity of explanation):
<snippet>
<content><![CDATA[
Hello, ${1:this} is a ${2:snippet}.
]]></content>
<tabTrigger>hello</tabTrigger>
<scope>source.python</scope>
</snippet>
Save this file as my_snippet.sublime-snippet.
Now, every time you open some .py file, typing hello followed by TAB, it will generate line:
Hello, this is a snippet.
with this and snippet being editable. You can learn more about snippets at here.
P.S.
The defined snippet for if statement in Javascript for example is:
<snippet>
<content><![CDATA[
if (${1:true}) {${0:$TM_SELECTED_TEXT}}
]]></content>
<tabTrigger>if</tabTrigger>
<scope>source.js</scope>
<description>if</description>
</snippet>
You can create your custom one, just name it differently and set trigger to be different from if + TAB

Emmet with sublime

I am trying to make something pretty easy and for some reason i can't. Generally with Emmet on html i don't have any problem, but i wanna make something custom. On javascript, when i type log i want on Tab should generate console.log() and write pointer inside (). I have searched folder with packages installed but i didn't find somewhere i could put code on. Also on the google i didn't find something that can help, i had this thing on the ATOM but i also can't find how they have it there.
You don't need Emmet for that, just create a snippet in Sublime Text.
Example:
<snippet>
<content><![CDATA[console.log($1)]]></content>
<tabTrigger>log</tabTrigger>
<scope>source.js</scope>
</snippet>
If you need this to work for HTML as well, you could change the scope to source.js,text.html

How can I create a short cut to wrap selection sublime text

I want to be able to select some content in sublime text, then press cmd+ctrl+l and then the selected content to be wrapped with an advanced version of markdown link. for example
[ $selection ](linkGoesHere "titleGoesHere")
You can likely get this working by writing a snippet or plugin to suit your needs.
You will be able to bind a plugin to your preferred keystroke, but snippets are triggered as you type in your file. Therefore a plugin is more likely to be your solution (since this requires some text to be written, selected, then the command executed), but if that ends up as a dead end, you might be able to use a snippet to accomplish the same task.

Sublime Text: ignore double quotes and display correct colors for HTML tags

I used to write HTML attribute values without double quotes. That makes the HTML code look very clean. Take my another answer as an example.
However, such a style causes Sublime to display tag colors incorrectly. In the following picture, since <div id=wrapper> has no double quotes around wrapper, Sublime does not show any color after that line (but how come everything looks OK before that line?).
Is there any way that I can set Sublime to ignore the double quotes and display correct colors?
What you need to do is redefine the syntax definitions in Sublime Text. You can also do this on the user level. Two great resources for doing this are here and here. They're very well written.
With that said, I’m using build 3083 right now and I can’t replicate your issue. A quick update might be all you need. I hope this helps.
Sublime Text has a setting called "HTML/XML Attributes" that can be customized to handle this scenario. You can add the following setting to your Sublime Text user settings file to ignore the double quotes:
Json
"auto_complete_html_attributes": false
This setting will turn off auto-completion for HTML/XML attributes in Sublime Text and allow the display of tag colors correctly. To access the user settings file, go to Preferences > Settings.

Resharper completion without overwriting existing code

In Resharper when I go back to edit some existing code.. eg. wanting to insert a String.Format into this code:
<td>
<%= Html.Encode(item.Address) %>
</td>
I move the cursor to before 'item' and type in 'String.F', getting Resharper's intellisense completion list that includes the 'Format' method.
However if I press TAB then it replaces 'item' with '.Format()'
Is there a way to use completing without replacing the existing text?
Stumbled upon using Enter instead of TAB to choose from the completion list. That does exactly what I want. It surrounds (in this case) 'item.Address' with the String.Format( .. ).
There are two techniques you can use.
The first is to use the Enter key, the second is to pop a space between where you are going to start typing and the next bit of code, which will prevent the next bit of code from being overwritten.
There is an actual setting now to disable this (annoying) behavior.
Go to the Options dialog (Menu -> Resharper -> Options).
In this Options dialog go to Environment -> IntelliSense -> Completion Characters.
Here you can set the Tab behavior to Insert instead of Replace.
Screenshot of Options
Resharper documentation about Completing Characters
This is an addition to the answer in 2010, for everyone that reaches this post via populair search engines ;)
You could also use the String.Format surround template but you may have to map a hotkey to it for easier access.
The keyboard command you want to use is called: Resharper_ForceCompleteItem. So if you go into Visual Studio's Tools > Options > Environment > Keyboard you could assign a keyboard shortcut there. Not sure if it would be possible to use Tab, though.

Resources