delete word after or around cursor in VIM

前端 未结 16 610
一向
一向 2020-12-07 06:59

I\'m now switching to VIM from TextMate. I found ^+W in INSERT mode very useful. However, I\'d like to delete not only the word before cursor, but

相关标签:
16条回答
  • 2020-12-07 07:23

    The below works for Normal mode: I agree with Dan Olson's answer that you should probably be in normal mode for most deletions. More details below.

    If the cursor is inside the word:
    diw to delete in the word (doesn't include spaces)
    daw to delete around the word (includes spaces before the next word).

    If the cursor is at the start of the word, just press dw.

    This can be multiplied by adding the usual numbers for movement, e.g. 2w to move forward 2 words, so d2w deletes two words.

    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.

    0 讨论(0)
  • 2020-12-07 07:23

    To delete all characters between two whitespaces, in normal mode:

    daW
    

    To delete just one word:

    daw 
    
    0 讨论(0)
  • 2020-12-07 07:29

    I made two mappings so I could get consistency in insert and out of insert mode.

    :map <'Key of your choice'> caw

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

    0 讨论(0)
  • 2020-12-07 07:31

    I think it's just daw

    daw - delete a word
    
    0 讨论(0)
  • 2020-12-07 07:31

    Do you mean like?

    dw
    
    0 讨论(0)
  • 2020-12-07 07:32

    Not exactly sure about your usage of "before" and "after", but have you tried

    dw
    

    ?

    Edit: I guess you are looking for something to use in insert mode. Strangely enough, there is nothing to be found in the docs, ctrl-w seems to be all there is.

    0 讨论(0)
提交回复
热议问题