Creating a keybinding for bold <strong> and italics <em>


#1

How do you create a snippet that will wrap text inside <strong> or <em> for example? Then simply create a keybinding for it?

Unfortunately this question has been asked a lot.

Once upon a time, there use to be a plugin for this purpose. But, it’s outdated now.

Here is my unsuccessful attempt so far – adding a <strong> keybinding:

/* 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>")
// keymap.cson

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

#2

ATOM must be restarted after adding the init coffee script and/or keymap. That’s the ticket!


#3

init.coffee is run when Atom starts up, yes.