vim:删除所有空格,直到下一个非空白字符

gws*_*gws 13 vi vim

说我有以下代码:

<p>
    Hello
</p>
Run Code Online (Sandbox Code Playgroud)

我想成功

<p>Hello</p>
Run Code Online (Sandbox Code Playgroud)

我想将光标置于第1行末尾的正常模式,所以在'>'上有一个命令删除所有空格直到下一个字符.我能想到的最接近的是动作

d/Hello
Run Code Online (Sandbox Code Playgroud)

删除所有内容直到Hello,但问题是它还删除了光标下的字符('>')所以我最终得到

<pHello
</p>
Run Code Online (Sandbox Code Playgroud)

你会怎么做?

Bir*_*rei 18

一种方法,您不需要多次重复此操作.

JxJx
Run Code Online (Sandbox Code Playgroud)

说明:

J           # Join current line with next one but substitute end of line with a space.
x           # Remove the space.
Jx          # Repeat same process for last line.
Run Code Online (Sandbox Code Playgroud)


kev*_*kev 6

tagvim中有一个文本对象:

  • 将光标放在标签内,按vat选择整个标签
  • :,它变成了:'<,'>
  • 类型j,它变成了:'<,'>j
  • Enter加入线

:help v_at

at          "a tag block", select [count] tag blocks, from the
            [count]'th unmatched "<aaa>" backwards to the matching
            "</aaa>", including the "<aaa>" and "</aaa>".
            See |tag-blocks| about the details.
            When used in Visual mode it is made characterwise.
Run Code Online (Sandbox Code Playgroud)

  • 这实际上并没有回答这个问题,因为`:join`添加了空格. (3认同)
  • `vatJ`会得到相同的结果. (2认同)