我现在从TextMate切换到VIM。我发现^+W在插入模式下非常有用。但是,我不仅要删除游标之前的单词,还要删除游标之后或周围的单词。
我做了一些谷歌搜索,但我唯一能找到的是^+W删除单词前光标。
我现在从TextMate切换到VIM。我发现^+W在插入模式下非常有用。但是,我不仅要删除游标之前的单词,还要删除游标之后或周围的单词。
我做了一些谷歌搜索,但我唯一能找到的是^+W删除单词前光标。
当前回答
我做了两个映射,以便在插入模式和退出插入模式时保持一致性。
:map <'Key of your choice'> caw
:imap <'Key of your choice'> <'Esc'> caw
其他回答
既然有这么多删除单词的方法,让我们来举例说明。
假设你编辑:
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 : delete the word under the cursor
caw : delete the word under the cursor and put you in insert mode
在旧的vi中,b将光标移动到单词的开头,在光标之前,w将光标移动到单词的开头,在光标之后,e将光标移动到单词的末尾,而dw将光标从光标删除到单词的末尾。
如果键入wbdw,则删除光标周围的单词,即使光标位于单词的开头或末尾。请注意,单词后面的空格被认为是要删除的单词的一部分。
在正常模式下删除两个空格之间的所有字符:
daW
只删除一个词:
daw
重复删除单词时,接受的答案失败,请尝试以下解决方案:
" delete current word, insert and normal modes
inoremap <C-BS> <C-O>b<C-O>dw
noremap <C-BS> bdw
它映射CTRL-BackSpace,也在正常模式下工作。