Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - delete line in insert mode

Tags:

vim

vi

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

like image 260
AK_ Avatar asked Jan 08 '18 23:01

AK_


2 Answers

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.

like image 156
Ingo Karkat Avatar answered Oct 24 '22 07:10

Ingo Karkat


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

like image 25
phd Avatar answered Oct 24 '22 07:10

phd