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 init.coffee 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 init.coffee:

atom.commands.add 'atom-text-editor',
'editor:wrap-with-strong': -&gt;
editor = atom.workspace.getActiveTextEditor()
for selection in editor.getSelections()
textToWrap = selection.getText()
selection.insertText("&lt;strong&gt;#{textToWrap}&lt;/strong&gt;")

Here’s the required code for keymap.cson:

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

Leave a Reply

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