Expanding Snippets Based On The Characters Before and After

There are different settings available if you want your Snippets to expand directly before or after certain text or keystrokes. Learn how to set “expand when” and “delimiters” below.

How to Expand Snippets When:

Say you want a Snippet for “-year-old” to expand right next to the number you type so that it looks like this “12-year-old,” but it only expands after a space, so that is looks like this “12 -year-old.”

  1. Choose the Snippet group that Snippet is in, then select the Group Settings cog towards the upper-right of the column that displays the snippets in the group.
  2. Set “Expand when:” to “Any character precedes abbreviation” if you want Snippets to expand next to any possible character, including letters. Select “All but letters and numbers precedes abbreviation” if you want Snippets to expand when directly next to punctuation or white space.

That group was likely set to “Whitespace precedes abbreviation” so that the Snippet would only expand after a blank space and not directly next to other characters.

Depending on your abbreviations, you may want to create a separate Snippet group specifically for these Snippets, and leave your other Snippets in a group set to “Whitespace precedes abbreviation.”

Here are a couple of Snippets perfect for a group that expands when typed next to any character:
– -year-old
– @companyemail.com
– anything you frequently type after a parenthesis () [] {}

HTML and code Snippet groups are also best set to expand next to any character. For this particular case, consider having these groups only expand in a certain app. This way, when writing an email you don’t have < p > < / p > tags suddenly appearing.

Technical Note: TextExpander only sees what you are typing, and cannot always notice the effects of particular keystrokes. For instance, in MacVIM, typing “i” while in navigation mode changes the context and meaning of subsequent keystrokes, but TextExpander cannot detect that, so if you type “iddate” your “ddate” Snippet will not expand unless it is in a group set to expand after “Any character precedes abbreviation”.

What Comes After: Delimiters

Control whether a typed abbreviation will expand based on what character you type right after it. The key you choose to control whether or not expansion happens is called the delimiter.

In the case of a Snippet like “vark,” you can type out “Aardvark” knowing your Snippet won’t expand as long as you don’t press your chosen delimiter key, such as Enter, Tab, or a punctuation key.

Choose one or more keys to act as delimiters in Preferences > Expansion > Set Delimiter. There are several to choose from, select the checkbox next to the delimiter keys you wish to use.

This setting is independent of the Expand when: setting, and unlike it, it is a global, all or nothing, setting.