---
title: "Keep code snippets in Markdown notes on the Mac"
author: Pedro Thomaz
source: https://coffeetext.app/blog/code-snippets-markdown-notes-mac
---

# Keep code snippets in Markdown notes on the Mac

> Checked November 2026 on macOS 26.

The `ffmpeg` command that shrinks a video. The SQL that finds duplicate rows. The `git` incantation for undoing the last commit. You look each one up every few months, and every time you find it somewhere different.

A folder of Markdown notes makes a good snippet library. It's plain text, so any editor opens it, Git can track it, and search finds it.

## One code block per snippet

A code block is the code between two lines of three backticks. Name the language after the first three:

````markdown
```sql
SELECT email, COUNT(*)
FROM users
GROUP BY email
HAVING COUNT(*) > 1;
```
````

Naming the language does two things: editors colour the code, and you can search for `sql` to find every SQL snippet you have.

Put a line above each block saying what it does, in the words you'd search for. "Find duplicate emails" beats a heading called "Query 3".

## How to arrange them

What works for most people:

- **One note per tool or topic**, such as `git.md`, `ffmpeg.md` and `postgres.md`, with a heading for each snippet.
- **A tag for the language** if your notes span several, such as `#bash` or `#python`.
- **The source, when it matters**: a link to the answer or the documentation it came from, so you can check it later.

A single long note is fine too, if your editor has an outline or a table of contents to jump around in.

## Writing code in Coffee

Coffee colours about 30 languages, including Swift, Python, JavaScript, TypeScript, JSON, HTML, CSS, shell, SQL, Go, Rust, Ruby, Java, Kotlin, C, C++, C#, PHP and YAML. Type three backticks and the language, or type / and choose the code block.

Inside a block:

- Return starts the next line as far in as the one you're on, so indented code stays lined up.
- Select several lines and press Tab to move them in, or ⇧Tab to move them out. Coffee uses the indent the block already has: a tab, four spaces or two.
- Line numbers are a setting, Line numbers in code in Settings › Writing. They're drawn beside the code and never go into the file.

## Copying the code without the backticks

The usual annoyance with snippets in Markdown is copying them: select the block and you get the backtick lines too.

In Preview, a Coffee code block has a Copy button at its top right, which appears when you point at the block. It copies the code alone and says Copied when it's done.

## Finding them again

Search is what makes a snippet library worth having. In Coffee, ⌘K searches every note, and the note opens where the words are. Because the notes are plain files, Spotlight finds them too, and so does `grep` in Terminal:

```
grep -rn "HAVING COUNT" ~/Notes
```

## Questions

### Why Markdown instead of a dedicated snippet app?

Your snippets stay ordinary files that any editor opens, and they sit beside the rest of your notes. A dedicated app can do more, such as filling in placeholders, if that's what you need.

### Which languages get colours?

In Coffee, about 30, from shell and SQL to Swift, Rust and Kotlin. A block with an unknown language is shown as plain code.

### Can I paste code without breaking its indentation?

Yes. A code block keeps every space as it is, and Tab and ⇧Tab use the indent the block already has.

### Do line numbers go into the file?

No. In Coffee they're drawn beside the code, and the file holds only the code.

---

Written by Pedro Thomaz, who makes Coffee, a Markdown editor for the Mac on macOS 15 or later, and for iPhone and iPad. It's free for 14 days with no card or account, then €3 a month, €29 a year, or €79 once with two years of updates. More at https://coffeetext.app/llms-full.txt
