How to duplicate these vim abbreviations in Atom?


#1
  1. This first one just surrounds a block of text with tags.

"Surrounds paragraph with tags.
iab tvb e/^$
ie

  1. This one just expands the text shown.
    iab ttitle
    <CR>—+ !!Title Here
    <CR>
    <CR>%TOC{depth=“5”}%
    <CR>
    <CR>—++ Item 1
    <CR>
    <CR>—++ Item 2
    <CR>

#2

In your init.coffee.

wrapSelection = (before, after) ->
  selections = atom.workspace.getActiveTextEditor().getSelections()

  for selection in selections
    selectedText = selection.getText()
    if selection.isEmpty()
      selection.insertText("#{before}#{selectedText}")
    else
      selection.insertText("#{before}#{selectedText}#{after}")

atom.commands.add 'atom-text-editor', 'custom:wrap-bold', ->
  open = '<b>'
  close = '</b>'

  wrapSelection(tag, tag)

This one just expands the text shown.

You can do that with a snippet.

"*":
  "ToC and Headers":
    prefix: "ttitle"
    body: """
---+ !!${1:Title Here}

%TOC{depth="5"}%

---++ ${2:Item 1}

---++ ${3:Item 2}
"""

#3

Thank you! The “*”: construct also answers my other question regarding using the same snippet in multiple file types.


#4

Selectors in snippets.cson work the same way as ones in config.cson. It’s all very consistent.