Vim:选择括号之间的文本,包括换行符

yan*_*olo 4 vim

我有这个代码:

import {
  one,
  two,
  three,
  four,
} from "../myfile";
Run Code Online (Sandbox Code Playgroud)

我正在尝试删除大括号之间的所有内容。我将光标放在大括号之间(或之上)的任意位置并键入di{。我得到这个:

import {
} from "../myfile";
Run Code Online (Sandbox Code Playgroud)

当我期待这个时:

import {} from "../myfile";
Run Code Online (Sandbox Code Playgroud)

有办法实现我想要的吗?

rom*_*inl 5

没有专门的方法来实现这一目标。

我是这样做的:

caB{}<Esc>
Run Code Online (Sandbox Code Playgroud)

但你可以这样做:

diBkJx
Run Code Online (Sandbox Code Playgroud)

或者像这样:

gwiBdiB
Run Code Online (Sandbox Code Playgroud)

或者可能有十几种其他方式。

如果您需要经常这样做,您可以将其映射到手指更容易操作的位置。

参考:

:help c
:help aB
:help d
:help iB
:help k
:help J
:help x
:help gw
Run Code Online (Sandbox Code Playgroud)

- -编辑 - -

FWIW,多年来我一直对这种行为感到困惑。

{我认为问题的核心在于同一行的后面没有文本,}同一行的前面也没有文本,但是哪个字符似乎很重要。

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";
Run Code Online (Sandbox Code Playgroud)

附加空格 附加非空白

import {xxx            If you prepend whitespace characters to },
  one,                 then they are ignored.
  two,
  } from "../myfile";
Run Code Online (Sandbox Code Playgroud)

仅在前面添加空格

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";
Run Code Online (Sandbox Code Playgroud)

前置混合字符

我真的不确定这里的理由。