Appearance
Input Rules
inputRules run synchronously in the editor while the user types. Use them for bracket pairs and typographic replacements. They are declarative: there is no code in the keystroke path.
json
"contributes": {
"inputRules": [
{ "pair": ["(", ")"] },
{ "pair": ["「", "」"] },
{ "pair": ["《", "》"] },
{ "match": "...", "replace": "…" },
{ "match": "->", "replace": "→" }
]
}Pairs
{ "pair": ["open", "close"] } — typing the opening character inserts the closing one after the caret; with a selection, it wraps the selection; Backspace in an empty pair removes both. Both must be single characters.
Replacements
{ "match": "text", "replace": "text" } — when the user finishes typing match, it is replaced with replace. match is plain text, not a regular expression.
Notes
- Extension rules apply on their own, whether or not the user has turned on Auto Pair Brackets and Quotes or Text Replacement. The user's own replacement rules are applied first.
- For changes that need logic or the whole document — spacing, linting, reformatting — register a formatter from
maininstead. Formatters run on demand from the command palette and apply as one undo step.
Chinese bracket pairing and Chinese–Latin spacing are built into Settings ▸ Writing ▸ Chinese Typography. Extensions can use the same input-rule contribution mechanism for other pairs.