Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 3 keyboard shortcut for bold

I can't for the life of me find how to make a keyboard shortcut to wrap a highlighted element in strong tags.

I know I can do Alt + Shift + w to wrap something in any html tag but you still have to type the tag. I want to be able to write my own shortcut for Ctrl + b for instance and that would wrap the element in tags

Any ideas?

like image 502
Xav Avatar asked Sep 29 '14 11:09

Xav


People also ask

How do I make text bold in Sublime Text?

Bold Text. Use double asterisks to show text as bold, or strong.

Is there a keyboard shortcut for bold?

Type the keyboard shortcut: CTRL+B.


1 Answers

You can do this with a custom key mapping. Go to Preferences -> Key Bindings-User and add the following:

{ 
    "keys": ["ctrl+super+b"], 
    "command": "insert_snippet", 
    "args": {"contents": "<strong>${0:$SELECTION}</strong>"}
}

If the file is empty when you open it, put an opening square bracket [ on the first line, and a closing bracket ] on the last line -- the file needs to be valid JSON. I used CtrlSuperB as the key binding, because CtrlB is already bound to the build command. (Super is the Windows key or the Command key, depending on your OS and keyboard.)

To use the command, you can select what you want surrounded in <strong> tags, and hit CtrlSuperB. The selection will remain selected - if you want to remove the selection and have the cursor after the closing tag, change the "contents" to this:

"<strong>$SELECTION</strong>"

Finally, after triggering the key combo, you can keep the selection, then hit Tab to move to the end of the closing tag:

"<strong>${1:$SELECTION}</strong>$0"
like image 178
MattDMo Avatar answered Sep 18 '22 15:09

MattDMo