Vim - select/yank/delete content between brackets including brackets
Yes. Use a
instead of i
, as
ya{
ya(
See
:help a{
:help a(
and more generally,
:help text-objects
:help 04.8
Does f{v%
or f(v%
do what you want? It moves your cursor to the next { or (, enters you into visual mode, and then moves your cursor to the corresponding closing } or ). If you're already past the scope you want to select, you can use a capital F
. Works just as well to jump to the closing } or ) first, too -- f}v%
.
Once you have what you want selected, you can y
, d
, x
, etc. it. The %
command works multi-line, too, so you can use this technique on large blocks of code if you wish (although f
and F
do not, so you have to start on either the first or last line).
EDIT: Better answer, seems to be exactly what you're looking for:
ya(
Replacing the i
in your original command with a
does exactly the same thing, except that it includes the '(' character. This is "yanking a block", whereas yi(
is "yanking an inner block".