How to cmd+b to string


Hi. I would comment that do not speak English properly, I hope you understand me .

I would create a very simple Snippet . I would simply press cmd + b on a text string and added the html tag:

Hello World
<strong>Hello World</strong>

I’ve been trying through and keymap.cson but I can not write the current text selection :

atom.commands.add 'atom-workspace', 'editor:insert-tag-snippet', ->
  selection = editor.getSelectedText() #Get string??
  snippetBody = '<${0:strong}>string here!!!!!!!!</${1:strong}>'
  atom.packages.activePackages.snippets?.mainModule?.insert snippetBody


'atom-workspace atom-text-editor:not([mini])':
  'alt-enter': 'editor:insert-tag-snippet'

I hope I explained correctly. Thank you very much.

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

You can’t do what you’re suggesting with a snippet. Snippets are triggered by typing some text and then pressing the expansion key, typically Tab. Keybindings like Cmd+B trigger commands. So if you wanted to make Cmd+B wrap selected text in <strong> tags, you could do something like this in your

atom.commands.add 'atom-workspace',
  'custom:wrap-with-strong': ->
    editor = atom.workspace.getActiveTextEditor()
    for selection in editor.getSelections()
      textToWrap = selection.getText()

Then you could use this in your keymap.cson:

  'cmd-b': 'custom:wrap-with-strong'



Just perfect. It’s just what I needed. Thanks for the help. ; )