User guide / Key bindings

Surround editing

Development reference · View source

m s, m r, and m d add, replace, and delete the pair of quotes or brackets around each selection, as in Helix. The keys after them name the pairs.

KeysAction
m s then a characterSurround each selection with that pair
m r then two charactersReplace the surrounding pair named by the first with the pair named by the second
m d then a characterDelete the surrounding pair

Examples:

Text and cursorKeysResult
name with name selectedm s ""name", selected with its quotes
(a, b) with the cursor on bm r ( [[a, b]
say("hi") with the cursor on hm d "say(hi)
[x, {y}] with the cursor on ym d m[x, y]
word under the cursorm i w m s **word*
  • Either bracket names its pair: ( and ) both mean parentheses, as do [/], {/}, and </>. Any other character is used on both sides, so m s * and m s | work.
  • m r and m d find the pair as m a does, from the character under each cursor: through the syntax tree first, then by a balanced scan of the text. They know the seven pairs m a knows, (, [, {, <, ", ', and `, and m for the closest of any of them.
  • With a pair selected, as m a ( leaves it, m d ( deletes that pair rather than the one outside it.
  • m s selects the result, delimiters included. m r and m d keep the selection on the text it covered.
  • If any cursor has no surrounding pair, nothing changes and the status line says so. Cursors inside the same pair edit it once.
  • Esc cancels while the keys are pending.