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

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


当前回答

正常模式:

daw : delete the word under the cursor    
caw : delete the word under the cursor and put you in insert mode 

其他回答

你是说像?

dw

以下内容适用于普通模式:我同意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.

我想这只是乌鸦

daw - delete a word

我做了两个映射,以便在插入模式和退出插入模式时保持一致性。

:map <'Key of your choice'> caw

:imap <'Key of your choice'> <'Esc'> caw

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

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

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