Adding a Keyboard Shortcut to Atom for Bolding Selected Text
I’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': -> editor = atom.workspace.getActiveTextEditor() for selection in editor.getSelections() textToWrap = selection.getText() selection.insertText("<strong>#{textToWrap}</strong>")
Here’s the required code for keymap.cson:
'atom-text-editor': 'alt-cmd-b': 'editor:wrap-with-strong'