Search code examples
linuxvimtext-editor

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?


Solution

  • 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.