You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VIM中删除单词及左侧空格?(禁用T/F类motion)

VIM 删除指定单词的操作问题

^ 表示VIM中光标所在字符
请勿使用 T 或 F 类motion作答

原始文本:

these are test words

需求:删除单词 test,最终得到:

these are words

光标在单词开头时的已知操作

当光标位于test开头:

these are test words
          ^

按下 dw 即可完成需求——w作为排他性motion,会删除test及其后的空格,且不会包含下一个单词words的首字符。

光标在单词末尾时的问题场景

当光标位于test末尾:

these are test words
             ^

尝试 dgE 会误删are的末尾字符e,得到错误结果:

these ar words

需要找到正确操作,实现删除test及其与are之间的空格,且不影响are。

可行解决方案

方案1:diw + dh

  • 按下 diw:删除当前完整单词(test),文本变为:
    these are  words
    
  • 按下 dh:删除光标前的多余空格,得到目标文本。

方案2:dge + db

  • 按下 dge:从光标位置向前删除到test的开头,删除test,文本变为:
    these are  words
    
  • 按下 db:向前删除到are的末尾,删掉中间的多余空格,得到目标文本。

方案3:b + dw

  • 按下 b:将光标移动到test的开头,此时光标位置与已知可行场景一致:
    these are test words
            ^
    
  • 按下 dw:执行已知的删除操作,直接得到目标文本。

内容的提问来源于stack exchange,提问作者ashish singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 16:22:41