Articles
Published · November 18, 2026

Snippet Tabstops and Placeholders: How $1 and Defaults Work

Snippet tabstops set where the cursor stops next. Placeholders add default text. Here is how $1, $0 and mirrored stops work in TextMate-style snippets.

Also in: Español中文हिन्दी

A snippet is text with stops in it. A tabstop such as $1 marks a place the cursor visits when you press Tab, and a placeholder such as ${1:default} is the same stop with starter text already filled in. If you keep a snippet library, this small grammar is most of what you need to write good ones.

You can store those snippets as plain Markdown files, and the syntax below is the part that makes them useful when an editor expands them.

Quick answer

Three rules cover most snippets.

  • $1, $2 and so on set the order the cursor visits. VS Code's snippet docs put it this way: the number is the order in which tabstops are visited, and $0 is the final cursor position.
  • ${1:foo} is a placeholder: a tabstop with a value.
  • Using the same number twice links the stops, so typing in one updates the other.

How it actually works

Tabstops and the final position

Here is the for loop snippet from the VS Code docs, as a JSON snippet body:

"body": ["for (const ${2:element} of ${1:array}) {", "\t$0", "}"]

Tab order follows the numbers, not the left-to-right position. The cursor lands on array first (stop 1), then element (stop 2). Then $0 takes it to the empty line inside the braces. VS Code describes traversal as ascending from one, with zero as a special case that always comes last and exits snippet mode.

If you leave out $0, the cursor ends at the end of the snippet. That is how the original TextMate manual describes it, and the Language Server Protocol spec says the same: the final tab stop defaults to the end of the snippet. Set $0 when you want the cursor somewhere else, such as the body of a block.

Placeholders carry default text

A placeholder is written ${number:text}. When you land on it, the default text is selected, so typing replaces it and Tab accepts it. That's why a good snippet reads like a filled-in example. You see the shape and change only what differs.

Mirrors

Reuse a number and the stops are linked. The LSP spec says multiple tab stops are linked and updated in sync. TextMate's manual shows the classic case, a LaTeX environment:

\begin{${1:enumerate}}
    $0
\end{$1}

Change enumerate to itemize in the first line and the \end line follows. Mirrors suit anything that must repeat. Think of a tag name, a function name, a class name.

Nesting

Placeholders can contain other placeholders. VS Code's example is ${1:another ${2:placeholder}}. TextMate's manual shows a practical use:

<div${1: id="${2:some_id}"}>
    $0
</div>

The first Tab stop offers an optional id attribute. If you accept it, the next Tab moves to the id value. If you overwrite the outer placeholder, TextMate removes the embedded stops, so the optional part disappears cleanly.

Choices and variables

Two more forms are worth knowing. A choice offers a short menu: ${1|one,two,three|}. A variable inserts a value from the editor: $name or ${name:default}. VS Code lists TM_FILENAME, TM_SELECTED_TEXT, CURRENT_YEAR and UUID among them. An unknown variable name is inserted as plain text and becomes a placeholder.

Escaping

A literal dollar sign needs a backslash. In VS Code and the LSP grammar, a backslash escapes $, } and \. Inside a JSON snippet file the backslash itself must be doubled:

"body": "\\$MyVar = 2"

That inserts $MyVar = 2. TextMate reserves $ and the backtick, and a } inside a default value must be escaped too.

When to use it (and when to skip it)

Use tabstops when a snippet has two or more spots you always edit. Use placeholders when the blank is easier to fill from an example. Use mirrors when the same word appears twice.

Skip the fancy parts when the snippet is a fixed block of text with nothing to change. A plain paste is simpler, and every extra stop is one more Tab to press.

Portability needs care. VS Code says its syntax follows TextMate's, except for interpolated shell code and \u, which it does not support. Other editors implement the grammar with their own gaps, so test a snippet where you plan to use it. For the bigger picture, see a workflow for managing code snippets.

How Carets fits in

Carets is a native notes and code editor for iPhone, iPad, and Mac. It doesn't change this syntax, and we aren't claiming it expands snippets for you. What it does well is the library side. Snippets live in plain-text and Markdown files, organized into files, projects, and tags, so a library stays portable and you can paste a snippet body into whatever editor expands it.

Syntax highlighting for code and config files helps when you're checking a body like the one above, with its braces and dollar signs. If you share a library with others, see sharing snippets across a team.

Get Carets on the App Store for iPhone, iPad, and Mac.

Frequently Asked Questions

What is the difference between a tabstop and a placeholder?

A tabstop is a bare cursor stop such as $1. A placeholder is a tabstop with default text, such as ${1:foo}. Both are visited in numeric order with Tab.

What does $0 do in a snippet?

$0 marks the final cursor position, where the cursor lands after the last Tab. Without it, the cursor ends at the end of the inserted snippet.

How do I insert a literal dollar sign in a snippet?

Put a backslash before it. VS Code and the LSP spec let you escape $, } and \ this way. In a JSON snippet file, double the backslash.

Do all editors use the same snippet syntax?

Many follow the TextMate-derived grammar, including VS Code and the Language Server Protocol, but details differ. For example, VS Code does not support interpolated shell code. Check your editor's docs.