AK_
AK_

Reputation: 2079

Vim - delete line in insert mode

Can I delete a line in insert mode?

Because currently I have to press <ESC>dd to be able to that, and I would like a quicker way to delete a line in insert mode

Upvotes: 22

Views: 19472

Answers (5)

Visual Sharp
Visual Sharp

Reputation: 3996

Press c + c (press c twice) will delete current line and enter insert mode.

Upvotes: 16

Tyler Dane
Tyler Dane

Reputation: 1069

You could also use _ to jump to first non-whitespace character and then C to delete to end of line and start insert.

You won't be in insert mode at the beginning, but you will be after running C. You also save yourself an esc keystroke and won't have to worry about mappings. Using _ also makes it easier to preserve formatting.

Upvotes: 2

phd
phd

Reputation: 95139

Use Ctrl+O in Insert mode to run one Normal mode command, so you can delete the current line without leaving Insert mode, with Ctrl+Odd.

See http://vimdoc.sourceforge.net/htmldoc/insert.html#i_CTRL-O

Upvotes: 33

SergioAraujo
SergioAraujo

Reputation: 11840

I would recommend creating an insert mapping

inoremap <Leader>k <C-o>dd

Remember in most cases is mapped to ",". For more information type: :h mapleader

Upvotes: 0

Ingo Karkat
Ingo Karkat

Reputation: 172778

If the cursor is at the end of the line, you can press <C-U> twice. The first one will clear the text before the cursor, the second one will remove the now empty line (and put the cursor at the end of the previous line).

That said, I would not use this often. Insert mode is for inserting; for all other edits, it's better to exit insert mode and use normal mode dd instead. Most power users quickly move into and out of various modes; that's what they were made for. Don't linger in insert mode for too long. I even exit it for "thinking pauses" of more than a few seconds.

Upvotes: 32

Related Questions