Search code examples
atom-editorcode-snippets

Wrong Behaviour of Snippets in Atom


I have created the following snippets in atom:

'.plain.text':
    'cdot':
        'prefix': '\c'
        'body': '\cdot'
    'vec':
        'prefix': '\v'
        'body': '\vec{$1}$2'
    'equation':
        'prefix': '\e'
        'body': """
            \begin{equation}

            $1

            \end{equation}

            """

The problem is that when I invoke them the first one appears correct, the second doesn't appears at all and the third one appears as:

\egin{equation}
end{equation}

Why is that happening? How can I fix it?


Solution

    • Remove backslash \ from prefixes (or customize with other characters which work)
    • Use double-escape (\\\\) when you want them to show on body.

    Snippet:

    '.plain.text':
      'cdot':
        'prefix': 'c'
        'body': '\\\\cdot'
      'vec':
        'prefix': 'v'
        'body': '\\\\vec{$1}$2'
      'equation':
        'prefix': 'equation'
        'body': """
            \\\\begin{equation}
    
            $1
    
            \\\\end{equation}
        """
    

    Note cursors will appear as desired but are moved in the images just to show snippet extension appearing.

    enter image description here enter image description here enter image description here