we help you to understand Python better

Is there some text that you type over and over again in Atom? Wouldn’t it be good if you could just type a few characters and replace this with blocks of code? After reading this, you know how to setup Atom to start typing the text for you!

Creating code snippets in Atom (macOS)

Snippets

To add a code snippet to Atom, take the following steps:

The .atom folder is hidden by default. Make sure to show all files and folders! The .atom folder contains a file called snippets.cson.

'.source.python':
  'clsEmployee':
    'prefix': 'clsEmployee'
    'body': """
class Employee:
    def __init__(self, name):
        self.name = name
"""

As you start typing, Atom offers your new snippet in the popup menu.

class Employee:
    def __init__(self, name):
        self.name = name

Variables in snippets

Atom snippets allow you to insert variables if needed. They are defined with a dollar sign:

'clsEmployee2':
  'prefix': 'clsEmployee2'
  'body': """
class Employee:
  def __init__(self, $1):
      self.$1 = $1
"""

You know Atom has a user folder and where to find the snippets file. You have learned how to add a new snippet to it and how to launch it from the editor. Now you can collect your most used code blocks and start your own snippet library!

Dive deeper into this topic with training?
By using this site, you acknowledge that you have read and understand our Cookie and Privacy Policy.