Using Atom’s Built‑in Snippets via snippets.cson
Learn how to add, test, and troubleshoot language‑agnostic snippets in Atom Editor using the snippets.cson file, with a concrete JavaScript console.log example.
16 Oct 2025, 17:32 UTC

Add a snippet in Atom
Atom’s built‑in snippet system lets you expand a short prefix into a larger block of text. The configuration lives in a file called snippets.cson inside your user ~/.atom directory.
Worked example: a JavaScript console.log snippet
.source.js:
'Log to console':
'prefix': 'cl'
'body': 'console.log($1);$2'After saving the file, run Window: Reload from the Command Palette (or press Ctrl+Shift+P and type 'reload'). Then open any file whose grammar is .source.js (a plain .js file), type cl and press Tab. The editor replaces the prefix with:
console.log(|);The cursor appears at $1; pressing Tab moves it to $2 after the semicolon.
Limits and common mistakes
- Scope selector must match: the snippet above only works in files whose grammar selector is
.source.js. Using the same prefix in a.tsor.htmlfile will not expand because the selector does not match. - Reload required: Atom reads
snippets.csonon start‑up and when you explicitly reload the window. Editing the file without a reload leaves the snippet inactive. - Malformed CSON is silent: a missing bracket, trailing comma, or incorrect indentation causes Atom to ignore the whole file without showing an error. Verify the file by opening Settings → Packages → snippets → Open Config Folder and checking that the tree view shows your entry.
- No literal tabs: Atom treats a tab character as the expansion trigger, so a literal tab inside
bodywill break the snippet. Use spaces instead. - Static text only: snippets cannot run commands or generate dynamic content. For logic you need a separate package or a custom keybinding.
How to verify a snippet is loaded
- Open a file with the matching grammar (e.g.,
test.js). - Type the prefix (
cl) and press Tab. If the template appears, the snippet is active. - Alternatively, open the Developer Tools (Ctrl+Shift+I or Cmd+Option+I on macOS) and run:
Atom.snippets.expand('cl', editor)If the snippet is loaded, the call returns an object containing the expanded text; otherwise it returns undefined.
Practical rollback
Since editing snippets.cson changes user state, you can revert by deleting the added lines or restoring a backup of the file, then reloading Atom.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.