如何在VIM中高效删除单词、冒号和逗号
我经常有这样的代码:
it "should do something", :focus do
...
end
当我想删除 , :focus
时,我通常会这样做
- Go to line 1:
1G
- Go to the colon:
f :
- 删除冒号(使用单词周围,这样我就可以重复它):
daw
- 删除
focus
(只需重复前面的):.
。 - 删除逗号(向左移动并用空格替换):
hr
。
有什么方法可以更有效地实现步骤 3-5?
I often have the piece of code like this:
it "should do something", :focus do
...
end
When I want to delete , :focus
I usually do
- Go to line 1:
1G
- Go to the colon:
f:
- Delete colon (using around word, so I can repeat it):
daw
- Delete
focus
(just repeat previous):.
. - Delete comma (move left and replace it with space):
hr<SPACE>
.
Is there any way steps 3-5 can be achieved more efficiently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过:
1G
转到第一行f,
转到逗号dE
删除,直到 WORD 的下一个结尾(WORD in大写字母是非空格的任何字符序列)。You can go:
1G
to go to first linef,
to go to the commadE
to delete till the next end of WORD (WORD in capital letters is any sequence of characters that is not space).将光标放在
,
上,您可以执行 v、e、e、d。或 d、2、e
With your cursor on the
,
you could do v, e,e,d.or d,2,e
使用光标或冒号可以执行 dF,dE。 dF, 部分将向后删除逗号(包括逗号)。然后 dE 将删除直到下一个空白字符。这样做的好处是,如果前面没有逗号,它仍然会做同样的事情。因此,
如果光标位于冒号上,则该宏将仅删除
:focus,
部分,尽管它会留下两个空格。With the cursor or the colon you can do dF,dE. The dF, part will delete backwards up to and including the comma. Then dE will delete up to the next whitespace character. The nice thing about this is that if there is no preceding comma this will still do the same thing. So with the code
If the cursor is on the colon this macro will delete just the
:focus,
part, although it will leave two spaces behind.你最好显示光标在哪里,但假设它在“end”之后,我会这样做:
You'd better show where your cursor is, but assuming it's after "end", I'd do this: