我现在从TextMate切换到VIM。我发现^+W在插入模式下非常有用。但是,我不仅要删除游标之前的单词,还要删除游标之后或周围的单词。
我做了一些谷歌搜索,但我唯一能找到的是^+W删除单词前光标。
我现在从TextMate切换到VIM。我发现^+W在插入模式下非常有用。但是,我不仅要删除游标之前的单词,还要删除游标之后或周围的单词。
我做了一些谷歌搜索,但我唯一能找到的是^+W删除单词前光标。
当前回答
在正常模式下删除两个空格之间的所有字符:
daW
只删除一个词:
daw
其他回答
要删除你的光标所在的整个单词,使用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,也在正常模式下工作。
既然有这么多删除单词的方法,让我们来举例说明。
假设你编辑:
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
在正常模式下删除两个空格之间的所有字符:
daW
只删除一个词:
daw
如果要删除游标之前的一定数量的字符,可以使用x。如果要删除游标之后的一定数量的单词,可以使用dw(以3个单词为例,可以使用3dw删除多个单词)。一般来说,如果要删除光标周围的内容,可以使用daw。