Neovim surround examples
The final ) in saiw) is a mini.surround identifier for a parentheses pair:
insert ( on the left and ) on the right. The final x in saiwx uses the
plugin's literal fallback: insert x on both sides.
Both characters are interpreted by mini.surround in that position. They are not
ordinary Vim commands such as x for deleting a character.
All examples use this config's default mini.surround mappings. Start in normal
mode with the cursor on the h in hello, unless stated otherwise. Spaces and
| separators in breakdowns are explanatory: do not type them. No leader key
is involved.
Which part comes from where?
For example, va( is Vim's visual selection plus the "around parentheses" text
object, enhanced here by mini.ai. It does not require mini.surround.
The selection language is reusable: viw selects an inner word, diw deletes
one, yiw copies one, and saiw) adds parentheses around one.
Step 1: choose the action
These actions come from mini.surround. Add needs a region because its wrapper does not exist yet. Delete and replace find an existing enclosing wrapper around the cursor.
Step 2 for add: choose the text
These selectors are called text objects:
A motion is another way to supply text to an action:
Bare { and a{ are different: { moves backward by paragraph; a{ identifies
an existing brace-delimited region. Similarly, bare ( is a backward-sentence
motion; it does not select parentheses.
Step 3 for add: choose the new wrapper
This table describes mini.surround's interpretation, not Vim's normal-mode meaning for the same characters.
Source: mini.surround's built-in surroundings.
There are other special identifiers, including f for function calls and t for
tags. Letters are not universally literal: x and i specifically use the
literal fallback in this default configuration.
Add: full before/after table
There is no separate saa command. In saa(i, one a finishes sa, and the next
starts a(. The final i is a literal wrapper, not an insert-mode command:
For the note (capital is across all files), saa(i produces
i(capital is across all files)i. sa(i instead uses the backward-sentence
motion and can reach back into preceding prose.
Delete and replace: find an existing wrapper
After sd or sr, ) means find an enclosing parentheses pair, not insert
one. A wrapper identifier describes the pair; the action determines what happens
to it. The documentation calls this an input surrounding, while the new
wrapper is an output surrounding.
Source: mini.surround input and output surroundings.
There is no iw or a( step after sd: the enclosing wrapper already defines
the boundaries. Only its two ends are removed; its contents remain.
Visual selection: choose the text first
v and V come from Vim's Visual mode.
Once text is selected, sa needs only the new wrapper. Pause after the selection
step to inspect the highlight.
Typing just v initially selects one character. That is why vsa{ wraps just
that character (with padded braces), rather than finding a word or parentheses.
Why not saVx for the whole line?
The meaning of V depends on the mode:
- Before
sa:Vstarts whole-line visual selection.Vsaxworks. - After
sa: Vim is waiting for a motion.Vforces a following motion to be linewise; it does not finish the selection by itself.saVxis incomplete as a surround operation becausexis not that motion.
See Vim's forced-motion rules.
An alternative without visual selection is sa_x: _ supplies a linewise
motion over the current line.
What does sa{x select?
sa{x means sa + backward-paragraph motion { + literal wrapper x.
It wraps the text traversed by the motion, with the starting cursor position
providing one boundary. It does not search for an opening brace.
For actual brace-delimited text, use saa{x: {hello} becomes x{hello}x.
Multi-character wrappers
For more selected text, choose a larger text object, motion, or visual
selection. For a wrapper containing more than one character, use ?.
Type saiw?, then answer the prompts:
For Markdown bold, enter ** at both prompts. Alternatively, 2saiw* repeats
the wrapper twice and produces **hello**. The leading 2 repeats the wrapper;
it does not select two words.
See mini.surround examples and counts.
Practice and further examples
Put (hello world) on a scratch line, with the cursor on hello:
- Type
va(, inspect the highlight, thensa}:{(hello world)}. - Undo with
u, then typesd):hello world. - Undo with
u, then typesr)]:[hello world].
This compares adding another layer, removing a layer, and replacing a layer on the same text.
- Official mini.surround video demo
- Official mini.surround examples
- Neovim editing tutorial
- Vim & Neovim reference
Tutorials for other surround plugins often use ys, ds, and cs. This config
uses mini.surround's sa, sd, and sr; the example commands above match those
bindings.

