学习 Vim:删除单词之间空格的最佳方法
我是一名经验丰富的 Windows 平台开发人员,我正在尝试自学如何使用 Vim。我很擅长正则表达式,并且了解如何使用 Vim 的原理。然而,我有一个具体的问题,虽然我有一个解决方案,但感觉好像应该有一个更好的解决方案。
我有一个文件,其中包含类似于以下内容的行:
CODE<tab><tab>Lorem ipsum dolor sit amet
CODE< 之间可能有可变数量的
或
字符/code> 和 Lorem
。假设光标在正常模式下位于 CODE 的“C”上,我想要做的是找到一个将产生以下输出的组合键,并将光标留在“E”之间在插入模式下,CODE
的 ' 和 Lorem
的 'L'。
CODELorem ipsum dolor sit amet
我当前的解决方案是使用以下按键序列:
w d ? \ s \ +
这可行,但在删除之前跳过我要删除的内容感觉不合逻辑。我觉得我应该移动到 CODE 的末尾并删除转发。我意识到这可能只是我不知道的 Vim 习惯用法。我也可能完全错过了 Vim 的一个关键知识。
实现我的目标的最佳方法是什么?
I'm an experienced developer on the Windows platform and I'm trying to teach myself how to use Vim. I am pretty good with regular expressions and understand the principles of how to use Vim. However, I have a specific problem, and although I have a solution, it feels as though there ought to be a better one.
I have a file which contains a line similar to the following:
CODE<tab><tab>Lorem ipsum dolor sit amet
There could be a variable number of <tab>
or <space>
characters between CODE
and Lorem
. Assuming the cursor is over the 'C' of CODE
in normal mode, what I want to be able to do is find a key combination that will produce the following output, and leave the cursor between the 'E' of CODE
and he 'L' of Lorem
in insert mode.
CODELorem ipsum dolor sit amet
My curent solution is to use the following key sequence:
w d ? \ s \ + <return>
This works, but it feels illogical to go past the thing I want to delete before I can delete it. I feel like I should move to the end of CODE
and delete forwards. I realise this could simply be a Vim idiom that I'm not aware of. I could also be totally missing a key piece of Vim knowledge.
What's the best way to achieve my goal?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
eldw 会做到的。
如果光标位于中间的一些空白, diw 将删除光标左右的空白。 (如果它位于单词中间的某个位置,则会删除该单词。)
eldw will do it.
If your cursor is in the middle of some whitespace, diw will delete whitespace left and right of the cursor. (If it is somewhere in the middle of a word, it will delete the word.)
一些替代方案:
Some alternatives: