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

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


当前回答

我想这只是乌鸦

daw - delete a word

其他回答

我想这只是乌鸦

daw - delete a word

你是说像?

dw

在插入模式下似乎没有内置的方法,这就是问题所在。其他一些答案对于普通模式是正确的,并指出可以创建自定义映射以在插入模式中添加功能。

老实说,你应该在正常模式下进行大部分删除操作。^W是整洁的,但我不确定我能想到一种情况,我宁愿这样做,而不是esc进入正常模式,并有更强大的删除命令在我的处置。

在这方面,Vim与许多其他编辑器(包括TextMate)非常不同。如果您正在高效地使用它,您可能会发现在插入模式上花费的时间并不多。

正常模式:

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

既然有这么多删除单词的方法,让我们来举例说明。

假设你编辑:

foo-bar quux

当光标在'bar'中的'a'上时调用一个命令:

foo-bquux  # dw:  letters then spaces right of cursor
foo-quux   # daw: letters on both sides of cursor then spaces on the right 
foo- quux  # diw: letters on both sides of cursor
foo-bquux  # dW:  non-whitespace then spaces right of cursor
quux       # daW: non-whitespace on both sides of cursor then spaces on the right
 quux      # diW: non-whitespace on both sides of cursor