Vim - select/yank/delete content between brackets including brackets
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Drifting Through My Dreams
--
Chapters
00:00 Vim - Select/Yank/Delete Content Between Brackets Including Brackets
00:18 Accepted Answer Score 0
00:33 Answer 2 Score 5
01:28 Answer 3 Score 110
01:42 Answer 4 Score 5
02:09 Thank you
--
Full question
https://superuser.com/questions/281814/v...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#vim
#avk47
ANSWER 1
Score 110
Yes. Use a
instead of i
, as
ya{
ya(
See
:help a{
:help a(
and more generally,
:help text-objects
:help 04.8
ANSWER 2
Score 5
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".
ANSWER 3
Score 5
One another way would be by following the below steps:
- place the cursor on the opening parenthesis
(
or braces{
- press
esc
key and pressv
to enter into the visual mode - now press the
%
symbol (this will select the whole text between parens inclusive) - press the key
y
to yank (i.e. copy) the text (pressd
if you rather want to cut it.)
Then, you can move the cursor wherever you want the new text to be pasted and then press p
for pasting the text there.
ACCEPTED ANSWER
Score 0
You can move the cursor over one bracket, and do vf{
or vf(
to bring you into visual mode and then select everything until (and including) the bracket.