Override default snippets in Atom
Asked Answered
A

2

8

I am trying to override default snippets in Atom, because I want to change the default script snippet from

<script charset="utf-8"></script>

to

<script src=""></script>

I have put the following into snippets.cson.

'.text.html':
  'Comment':
    'prefix': 'com'
    'body': '<!-- $1-->'
  'Script':
    'prefix': 'script'
    'body': '<script src="$1"></script>'

My 'com' snippet works fine. But script results in the default snippet, not my new one.

Azaleeazan answered 26/8, 2014 at 15:25 Comment(0)
L
3
  1. Add a snippet that overwrites an existing snippet
  2. Quit Atom
  3. Start Atom
  4. Trigger the newly added snippet, and the original snippet will trigger
  5. Open the ~/.atom/snippets.cson file and Save the file (no changes need be made)
  6. Trigger the snippet again and it will use the customized version

Apparently its a bug right now.

via https://github.com/atom/atom/issues/2695

Lukas answered 26/8, 2014 at 15:30 Comment(3)
Just quitting and starting again worked for me on Atom 1.2.4Pung
Hey, sorry but I don't use Atom anymore so I have no idea if this works on newer versions. It seems like since this was a bug they would have fixed it eventually though.Lukas
is there a file which holds all the atom core snippets so i can see how it's done by default?Halliday
B
0

As of 1.19.5 I can override atoms default snippets by using the traditional procedure for creating snippets, which is written in coffeescript. For example, overwriting my require method looks something like . . .

    '.source.[*yourlanguage*]':

    'Require':
    'prefix': 'r'
    'body': "require '$1' "

More descriptively

  • Navigate to "snippets" via the file dropdown menu.

  • Follow the instructions listed, or continue with me.

  • Copy and paste the code I've provided above, below. Replace the yourlanguage with the language you are writing the code for you.

  • Open a new file, type the character following the 'prefix':, press tab.

  • This should give you enough information to contextually figure out how to both overwrite, and write original snippets.

Bogie answered 14/9, 2017 at 3:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.