我有这段代码:
import {
one,
two,
three,
four,
} from "../myfile";
我想删除花括号内的所有内容。我把光标放在花括号之间(或上面),然后输入 di{
。结果得到:
import {
} from "../myfile";
当我期望的是这个:
import {} from "../myfile";
有没有办法实现我想要的目标?
我有这段代码:
import {
one,
two,
three,
four,
} from "../myfile";
我想删除花括号内的所有内容。我把光标放在花括号之间(或上面),然后输入 di{
。结果得到:
import {
} from "../myfile";
当我期望的是这个:
import {} from "../myfile";
有没有办法实现我想要的目标?
没有专门的方法来实现这一点。
以下是我实现的方式:
caB{}<Esc>
但你可以像这样做:
diBkJx
或者像这样:
gwiBdiB
或者可能有数十种其他方式。
如果需要频繁地这样做,您可以将它映射到更容易用手指操作的东西上。
参考:
:help c
:help aB
:help d
:help iB
:help k
:help J
:help x
:help gw
---编辑---
就我个人而言,多年来我一直对这种行为感到困惑。
我认为问题的核心在于,在同一行中的 {
之后没有文本并且在同一行中的 }
之前也没有文本,但似乎重要的是哪个字符。
import {___(3 spaces) If you append characters of _any_ kind to {,
one, including whitespace, then the selection
two, includes them.
} from "../myfile";
import {xxx
one,
two,
} from "../myfile";
import {xxx If you prepend whitespace characters to },
one, then they are ignored.
two,
} from "../myfile";
import {xxx If there is even _one_ non-whitespace
one, character in those prepended to },
two, then the selection includes them all.
x } from "../myfile";
我真的不确定这里的原理。
diB
会这样表现?帮助文档说,文本对象应该选择括号之间的文本,这意味着它应该包括换行符。 - yankolo