0

In insert mode I want to delete all text from the cursor to the beginning of a line and stay in insert mode.

Here is the mapping I tried:

inoremap DD <ESC>c0

and this almost works. In the following line (in insert mode)

This is a test line 
              ^
           cursor

in insert mode cursor goes 1 step further than just typed symbol (t in my case). And if I press DD, I will get

t line

but want just

 line
^
cursor

with the space the cursor pointed.

Is there a way to do this in vim?

1
  • just move right first then...
    – minseong
    Commented Sep 30, 2016 at 21:33

1 Answer 1

2

There's actually already a builtin for this. :h i_<C-u>:

                *i_CTRL-U*
CTRL-U          Delete all entered characters in the current line (see
    |i_backspacing| about joining lines).

You could map this, e.g.

inoremap DD <C-u>

But this might interfere with typing. I would encourage you to just learn to use <C-u> instead.

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.