Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete till end of current parenthesis block in vim

Say I am editing this json

{
  "a": {"language": "python"},
  "b": {},
  "c": {"language": "java"},
  "d": {"encoding": "utf-16"}
}

My cursor is at b of "b": {}. I want to delete till the end of current {} block. So it'll look like,

{
  "a": {"language": "python"},
  "
}

Looks little odd. But explains what I want.

How can I do that in Vim?

like image 456
Shiplu Mokaddim Avatar asked Dec 10 '22 13:12

Shiplu Mokaddim


2 Answers

You can use d]}.
From :help ]}:

                                    *]}*
]}          go to [count] next unmatched '}'.
            |exclusive| motion.

The help also says that this is one of the motion's use case:

The above four commands can be used to go to the start or end of the current
code block.  It is like doing "%" on the '(', ')', '{' or '}' at the other
end of the code block, but you can do this from anywhere in the code block.
like image 142
Marth Avatar answered Dec 31 '22 21:12

Marth


for your example, d]] works too. It is easier to press. However, ]} is better, since it works no matter which column the { or } sits on.

like image 36
Kent Avatar answered Dec 31 '22 21:12

Kent