<C-w> deletes a (small-)word in insert mode, but I often want to delete the Word (to last whitespace) I've most recently typed. I tried

inoremap <C-_> <C-o>dB

which kind-of works -- except that at the end of the line, <C-o> moves the cursor left one character (and so the last character survives the deletion).

Other options? More generally, how do I use <C-o> in insert-mode mappings without the end-of-line off-by-one problem? Can the normal-mode cursor (which is what <C-o> summons) be placed "temporarily" beyond the line-end?

1 Answer 1


All you need to do is insert <C-\> before the <C-o>.

inoremap <C-_> <C-\><C-o>dB

Help for i_CTRL-\_CTRL-O says:

CTRL-\ CTRL-O : like CTRL-O but don't move the cursor

That's it. Well except for a caveat or two which I'll reproduce here for your convenience ;) ...

The CTRL-O command sometimes has a side effect: If the cursor was beyond the end of the line, it will be put on the last character in the line. In mappings [you can] use CTRL-\ CTRL-O, but then beware of the cursor possibly being beyond the end of the line. Note that the command following CTRL-\ CTRL-O can still move the cursor, it is not restored to its original position.

While quickly testing your mapping with the fix against the scenario you describe I didn't see any issues so you can probably safely ignore all of that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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