Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #436 - Recover from accidental Ctrl-U

Created: March 7, 2003 2:23 Complexity: basic Author: John Wright Version: 5.7 Karma: 17/8 Imported from: Tip#436

If you've accidently typed control-U to delete a line then accidently typed ESC straight after that because you've been using web forms and ESC in IE forms is like undo and basically you really didn't want to do that then you should do this:


let @a = @.

"aP


The . register is basically everything you've just typed in input mode including the control-U. When you paste this buffer it acts like you're typing it again and deletes the line. You need to reassign it to another register with the let command before you can paste it properly and get at your nice input.

Comments

If you don't want to change register a, use

dis .

to see the contents of the . register, than yank with the mouse. /Siegfried

sb--AT--c-lab.de , March 7, 2003 3:36


Is there any use for Ctrl-U in insert mode? If not, why not simply use the following mapping and not have to worry about losing anything if you press C-U while you are in insert mode?

imap <C-U> <ESC>a 


Anonymous , March 7, 2003 7:27


To search for an insert mode control key, use the form:

:h i_ctrl-<letter> 

e.g.

:h i_ctrl-u 


jaldripublic at comcast dot net , November 17, 2003 7:43


Try the following to paste all of ". except the <C-U>:

put ='<C-R><C-R>.<BS>'

On the command-line, <C-R><C-R> inserts *any* text (including <C-U>) literally. The backspace, <BS>, simply deletes the <C-U>. The quotes are necessary since we're using the expression register, "=

Once you get used to using it, the expression register is *very* useful.

h c_CTRL-R_CTRL-R
h "=

Anonymous , November 22, 2004 4:22


Advertisement