我现在从TextMate切换到VIM。我发现^+W在插入模式下非常有用。但是,我不仅要删除游标之前的单词,还要删除游标之后或周围的单词。

我做了一些谷歌搜索,但我唯一能找到的是^+W删除单词前光标。


当前回答

以下内容适用于普通模式:我同意Dan Olson的回答,对于大多数删除操作,您应该处于正常模式。详情如下。

如果光标在单词内: 在单词中删除(不包括空格) 删除单词周围(包括下一个单词前的空格)。

如果光标位于单词的开头,只需按dw。

这可以通过添加用于移动的常用数字来相乘,例如2w向前移动2个单词,因此d2w删除两个单词。

Insert Mode ^w The idea of using hjkl for movement in Vim is that it's more productive to keep your hands on the home row. At the end of a word ^w works great to quickly delete the word. If you've gone into insert mode, entered some text and used the arrow keys to end up in the middle of the word you've gone against the home-row philosophy. If you're in normal mode and want to change the word you can simply use the c (change) rather than d (delete) if you'd like to completely change the word, and re-enter insert mode without having to press i to get back to typing.

其他回答

以下内容适用于普通模式:我同意Dan Olson的回答,对于大多数删除操作,您应该处于正常模式。详情如下。

如果光标在单词内: 在单词中删除(不包括空格) 删除单词周围(包括下一个单词前的空格)。

如果光标位于单词的开头,只需按dw。

这可以通过添加用于移动的常用数字来相乘,例如2w向前移动2个单词,因此d2w删除两个单词。

Insert Mode ^w The idea of using hjkl for movement in Vim is that it's more productive to keep your hands on the home row. At the end of a word ^w works great to quickly delete the word. If you've gone into insert mode, entered some text and used the arrow keys to end up in the middle of the word you've gone against the home-row philosophy. If you're in normal mode and want to change the word you can simply use the c (change) rather than d (delete) if you'd like to completely change the word, and re-enter insert mode without having to press i to get back to typing.

在旧的vi中,b将光标移动到单词的开头,在光标之前,w将光标移动到单词的开头,在光标之后,e将光标移动到单词的末尾,而dw将光标从光标删除到单词的末尾。

如果键入wbdw,则删除光标周围的单词,即使光标位于单词的开头或末尾。请注意,单词后面的空格被认为是要删除的单词的一部分。

你应该做的是创建一个特定键的imap到一系列的命令,在这种情况下,命令会让你进入正常模式,删除当前的单词,然后把你放回插入:

:imap <C-d> <C-[>diwi

要删除你的光标所在的整个单词,使用diw删除你的光标所在的整个单词,并将你置于插入模式,如果你不想删除整个单词,请使用ciw删除你所在的dw/cw

重复删除单词时,接受的答案失败,请尝试以下解决方案:

" delete current word, insert and normal modes
inoremap <C-BS> <C-O>b<C-O>dw
noremap <C-BS> bdw

它映射CTRL-BackSpace,也在正常模式下工作。