我现在从TextMate切换到VIM。我发现^+W在插入模式下非常有用。但是,我不仅要删除游标之前的单词,还要删除游标之后或周围的单词。
我做了一些谷歌搜索,但我唯一能找到的是^+W删除单词前光标。
我现在从TextMate切换到VIM。我发现^+W在插入模式下非常有用。但是,我不仅要删除游标之前的单词,还要删除游标之后或周围的单词。
我做了一些谷歌搜索,但我唯一能找到的是^+W删除单词前光标。
当前回答
既然有这么多删除单词的方法,让我们来举例说明。
假设你编辑:
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
其他回答
我不仅要删除光标之前的单词,而且要删除光标之后或周围的单词。
在这种情况下,可以将OP提出的解(即使用<c-w>)与接受的答案结合起来,得到:
inoremap <c-d> <c-o>daw<c-w>
或者(更短的解决方案):
inoremap <c-d> <c-o>vawobd
样例输入:
word1 word2 word3 word4
^------------- Cursor location
输出:
word1 word4
你应该做的是创建一个特定键的imap到一系列的命令,在这种情况下,命令会让你进入正常模式,删除当前的单词,然后把你放回插入:
:imap <C-d> <C-[>diwi
你是说像?
dw
要删除你的光标所在的整个单词,使用diw删除你的光标所在的整个单词,并将你置于插入模式,如果你不想删除整个单词,请使用ciw删除你所在的dw/cw
既然有这么多删除单词的方法,让我们来举例说明。
假设你编辑:
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