How do I select the surrounding parentheses similar to vim-surround? I know I can do <alt-a>(
or m
to select the text in between, but how do I get two cursors at the end?
Asked
Active
Viewed 1,043 times
2 Answers
4
vim-surround
functionality was implemented by kakoune-surround plugin, but, if you prefer "vanilla experience", you can change parenthesis to, say, square brackets using select
:
ms\(|\)<return><space>r]<alt-n>r[
m
— select the closest matching parenthesis (or by<alt-a>)
, as you mentioned);s\(|\)<return>
— select(
and)
using regex;<space>
— clear selections (cursor will be positioned on the last match);r]
— change)
to]
;<alt-n>
— select previous match (it will be(
according to our regex);r[
— change(
to[
.

Aleksandr Fedchenko
- 56
- 1
- 4
4
To complement Aleksandr answer, at the beginning you can use <a-S>
after <a-a>(
. It will select the selection boundaries, which in this case happen to be the parens.

Delapouite
- 9,469
- 5
- 36
- 41
-
1This is really nice - as it works more intuitively for all kinds of blocks, but it breaks the rest of Aleksandr's command since you can't jump to the other paren after modifying one of them. How do you deal with sending different edits to the two different cursors that this breaks into? – Conrad.Dean Oct 25 '20 at 15:55
-
1The sequence `r{
r}` will first replace both cursors with an opening brace, then reduce the selection to only the second cursor, and finally replace it with a closing brace. The problem is that this won't work if you're trying to change multiple sets of parenthesis at the same time. – Connor McKay Dec 17 '20 at 20:46