在vim中删除直到当前括号块结束

问题描述 投票:0回答:3

假设我正在编辑这个 json

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

我的光标位于

b
"b": {}
处。我想删除直到当前
{}
块的末尾。所以它看起来像,

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

看起来有点奇怪。但解释了我想要什么。

我怎样才能在 Vim 中做到这一点?

linux vim text-editor
3个回答
11
投票

您可以使用

d]}

来自
:help ]}

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

帮助还说这是该动议的用例之一:

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.

2
投票

对于您的示例,

d]]
也有效。按压起来比较容易。 然而,
]}
更好,因为无论
{ or }
位于哪一列,它都可以工作。


0
投票

另一种方法是:

V f ^ } k k d
© www.soinside.com 2019 - 2024. All rights reserved.