I need make a shortcut that will be adding certain text at the cursor, eg {sometext}, how can this be done?
Insert a Text box Press and release ALT, N, and then press X. Press the arrow keys to select the Text box that you want, and then press ENTER.
Begin keyboard shortcuts with CTRL or a function key. Press the TAB key repeatedly until the cursor is in the Press new shortcut key box. Press the combination of keys that you want to assign. For example, press CTRL plus the key that you want to use.
Select the Key Bindings - User item under Sublime's Preferences, then add the following example line:
{"keys": ["ctrl+shift+c"], "command": "insert_snippet", "args": {"contents": "hello!"}}
This will add a CTRL+SHIFT+C shortcut to insert the hello! snippet.
By the way, don't forget to add a comma to the previous key binding hash so that all but the last line end with a comma. i.e.:
[
{"keys": ["..."], "command": "..." },
{"keys": ["..."], "command": "..." },
{"keys": ["..."], "command": "..." },
{"keys": ["ctrl+shift+c"], "command": "insert_snippet", "args": {"contents": "hi!"}}
]
If you already have a snippet file written, say at Packages/User/myFunction.sublime-snippet
, you can use
Add this to Preferences > Key Bindings - User
{ "keys": ["ctrl+1"], "command": "insert_snippet", "args": {"name": "Packages/User/myFunction.sublime-snippet"} }
This example binds the snippet to CTRL + 1.
I found the info on Christopher Millward's blog.
@skyisred I think the question is already very well answered to the point. But web-developers often will need to generate dummy content to fill the elements. Say "Lorem ipsum".
Type lorem
and hit Tab
Sublime will generate the complete Lorem ipsum dummy text for you.
If you really want to do it with a shortcut
Go to
[On Windows] Preferences > Key Bindings - User
[On OS X] Sublime Text > Preferences > Key Bindings - User
[
{"keys": ["ctrl+alt+i","ctrl+alt+s"], "command": "insert_snippet","args": {"contents": "A small snippet"}},
{"keys": ["ctrl+alt+i","ctrl+alt+m"], "command": "insert_snippet","args": {"contents": "A medium-sized snippet, just good enough to fill in a normal span element."}},
{"keys": ["ctrl+alt+i","ctrl+alt+l"], "command": "insert_snippet","args": {"contents": "A large snippet, a little more than the medium snippet and just good enough to fill in a paragraph element.This will make your work so much more easier."}}
]
I have written an article on creating custom keyboard shortcuts in Sublime Text which might be helpful to you to create shortcuts for other common operations in Sublime Text.
I did something a little bit more complex and complete too. Like \emph{} when you press ctrl+l, ctrl+e ... My job here is to write \textit{} when you press ctrl+shift+i.
Go to Preferences > Browse Packages. There inside you should save a file named "Text ital.sublime-snippet" for example. Inside of this file put this code:
<snippet>
<description>Italic text</description>
<content><![CDATA[
\\textit{${1:$SELECTION}}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<scope>text.tex.latex</scope>
</snippet>
Then go to Preferences > Key Bindings. There inside you will write this:
[
{ "keys": ["ctrl+shift+i"],
"context": [
{"key": "selector", "operator": "equal", "operand": "text.tex.latex"}],
"command": "insert_snippet", "args": {"name":"Packages/LaTeXTools/Text ital.sublime-snippet"}}
]
Remind that Packages/LaTeXTools/ is the Location of Preferences > Browse Packages. Remind too that you should insert a comma between two different shortcuts you create.
Hope it works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With