如何在VIM中高效删除单词、冒号和逗号

发布于 2024-12-25 03:38:28 字数 422 浏览 4 评论 0原文

我经常有这样的代码:

it "should do something", :focus do
  ...
end

当我想删除 , :focus 时,我通常会这样做

  1. Go to line 1: 1G
  2. Go to the colon: f :
  3. 删除冒号(使用单词周围,这样我就可以重复它):daw
  4. 删除focus(只需重复前面的):.
  5. 删除逗号(向左移动并用空格替换):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

  1. Go to line 1: 1G
  2. Go to the colon: f:
  3. Delete colon (using around word, so I can repeat it): daw
  4. Delete focus (just repeat previous): ..
  5. Delete comma (move left and replace it with space): hr<SPACE>.

Is there any way steps 3-5 can be achieved more efficiently?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ゞ记忆︶ㄣ 2025-01-01 03:38:29

您可以通过:

  1. 1G 转到第一行
  2. f, 转到逗号
  3. dE 删除,直到 WORD 的下一个结尾(WORD in大写字母是非空格的任何字符序列)。

You can go:

  1. 1G to go to first line
  2. f, to go to the comma
  3. dE to delete till the next end of WORD (WORD in capital letters is any sequence of characters that is not space).
债姬 2025-01-01 03:38:29

将光标放在 , 上,您可以执行 veed

d2e

With your cursor on the , you could do v, e,e,d.

or d,2,e

萌︼了一个春 2025-01-01 03:38:29

使用光标或冒号可以执行 dF,dEdF, 部分将向后删除逗号(包括逗号)。然后 dE 将删除直到下一个空白字符。这样做的好处是,如果前面没有逗号,它仍然会做同样的事情。因此,

if :focus, "should do something" do

如果光标位于冒号上,则该宏将仅删除 :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 :focus, "should do something" do

If the cursor is on the colon this macro will delete just the :focus, part, although it will leave two spaces behind.

望喜 2025-01-01 03:38:29

你最好显示光标在哪里,但假设它在“end”之后,我会这样做:

?",<CR>ldt<space>.

You'd better show where your cursor is, but assuming it's after "end", I'd do this:

?",<CR>ldt<space>.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文