Vim Tips Wiki
m (Accidently typed control-u and lost your input? moved to Recover from accidental Ctrl-U: Page moved by JohnBot to improve title)
(Change to TipImported template + severe manual clean)
Line 1: Line 1:
 
{{Dodgy}}
 
{{Dodgy}}
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=436
 
|id=436
  +
|previous=434
|title=Accidentally typed control-u and lost your input?
 
  +
|next=437
|created=March 7, 2003 2:23
+
|created=March 7, 2003
 
|complexity=basic
 
|complexity=basic
 
|author=John Wright
 
|author=John Wright
 
|version=5.7
 
|version=5.7
 
|rating=17/8
 
|rating=17/8
 
}}
|text=
 
If you've accidentally typed control-U to delete a line then accidentally 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:
+
If you've accidentally typed control-U to delete a line then accidentally 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==
:let @a = @.
 
 
If you don't want to change register a, use
 
:dis .
   
 
to see the contents of the . register, than yank with the mouse.
"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?
+
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
+
imap <C-U> <ESC>a
   
 
'''Anonymous'''
 
, March 7, 2003 7:27
 
 
----
 
----
To search for an insert mode control key, use the form:
+
To search for an insert mode control key, use the form:
   
:h i_ctrl-<letter>
+
:h i_ctrl-<letter>
   
  +
For example
e.g.
 
   
:h i_ctrl-u
+
: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>:
+
Try the following to paste all of ". except the <C-U>:
:put ='<C-R><C-R>.<BS>'
+
: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, "=
+
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.
+
Once you get used to using it, the expression register is *very* useful.
   
  +
<pre>
:h c_CTRL-R_CTRL-R
+
:h c_CTRL-R_CTRL-R
 
:h "=
 
:h "=
  +
</pre>
   
'''Anonymous'''
 
, November 22, 2004 4:22
 
 
----
 
----
<!-- parsed by vimtips.py in 0.496167 seconds-->
 
 
Why delete? [[User:Bastl|bastl]] 09:05, 26 July 2007 (UTC)
 
 
----
 
Let's discuss this at [[Category talk:Candidates for deletion]] so we keep the history of our discussion.
 
 
--[[User:JohnBeckett|JohnBeckett]] 10:56, 26 July 2007 (UTC)
 

Revision as of 06:19, 4 November 2007

Tip 436 Printable Monobook Previous Next

created March 7, 2003 · complexity basic · author John Wright · version 5.7


If you've accidentally typed control-U to delete a line then accidentally 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.


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

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

:h i_ctrl-<letter>

For example

:h i_ctrl-u

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 "=