Atom Text Editor

Adding a Keyboard Shortcut to Atom for Bolding Selected Text

Atom EditorI’ve been using Atom as an editor for a while now and it has always frustrated me that there isn’t a built in key mapping for wrapping selected text in a web file (html, php, etc) with a <strong> tag in order to bold the selected text. I got by initially but using the atom-wrap-in-tag package but this still requires you to type “strong” every time after you type alt-cmd-w; this is more cumbersome than should be necessary.

I did discover a great way to do this that involves simply editing the Atom file and the keymap.cson file.  After adding the code, and then restarting Atom, you can hit alt-cmd-b to wrap your selected text in <strong> tags. So simple!

Here’s the required code for

atom.commands.add 'atom-text-editor',
'editor:wrap-with-strong': -&gt;
editor = atom.workspace.getActiveTextEditor()
for selection in editor.getSelections()
textToWrap = selection.getText()

Here’s the required code for keymap.cson:

'alt-cmd-b': 'editor:wrap-with-strong'

Leave a Reply

Your email address will not be published. Required fields are marked *