2

I frequently use <C-w> in insert mode to back up when I mistype things. I've noticed some odd behavior if I start insert mode when in the middle of a word.

For example, if I have the following line (cursor location indicated by ^):

I love to use CamelCase
                   ^

When I am at that cursor location and do the key combination i<End><C-w>, I am left with the following:

I love to use Camel
                   ^

I expected that <C-w> would erase up to the beginning of CamelCase since that is a word. Is <C-w> only supposed to erase up to the beginning of where I started inserting? Or is there some setting I have to flip to get it to delete the entire word?

If I press <C-w> again, it does erase the rest of the word. I just wasn't expecting a word boundary to appear where insert mode started.

This is using Vim 8.1 (2018 May 18) for Windows.

3

This is documented behaviour. Deleting text before the insert start location is controlled by the 'backspace' option, and :help 'backspace' says this:

start: allow backspacing over the start of insert; CTRL-W and CTRL-U stop once at the start of insert.


If you really want <C-w> to behave as you "expect", here's a convoluted mapping (the different handling depending on whether the cursor is at the end of the line or not is to make sure that the last character is handled correctly: if you do db when the cursor is at the end of the line, the last character is not deleted; if you do vbd when the cursor is not at the end of the line, the following character is deleted):

inoremap <expr> <C-w> col('.') == len(getline('.'))+1 ? "\<C-o>vb\"_d" : "\<C-o>\"_db"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.