Vim Tips Wiki
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
  +
{{review}}
 
{{TipImported
 
{{TipImported
 
|id=637
 
|id=637
Line 19: Line 20:
 
This mapping switches to normal mode, undoes the last insertion and takes it as a command.
 
This mapping switches to normal mode, undoes the last insertion and takes it as a command.
   
  +
Most times I need it, if I typed dd and the line still remains because of Insert-Mode and the unwanted 'dd' ist somewhere in my text.
This can allow you to easily do what you intended when you enter insert mode but change your mind later (and forget you're still in insert mode). Unfortunately, it isn't all that useful by itself, because a text insertion counts as a single operation in the [[Recover_from_accidental_Ctrl-U#Explanation|undo sequence]]. Therefore, it only works if the ONLY text you enter is a normal-mode command.
 
   
 
==Comments==
You can make this mapping more useful by combining it with the following autocmd:
 
  +
I guess you meant:
   
 
<pre>
 
<pre>
  +
inoremap <somekey> <Esc>u:@.
autocmd CursorHoldI * call feedkeys("\<C-G>u", 'tn')
 
 
</pre>
 
</pre>
   
  +
----
This will break the undo sequence if you leave Vim in insert mode for too long. This means if you accidentally leave Vim in insert mode after a lengthy insertion, the mapping given at the beginning of the tip will only undo and execute the last inserted text.
 
  +
I prefer
   
  +
<pre>
==References==
 
  +
inoremap <somekey> <Esc>u@. i
*{{help|@}}
 
  +
</pre>
*{{help|quote.}}
 
*{{help|CursorHoldI}}
 
*{{help|feedkeys()}}
 
*{{help|ins-special-special}}
 
   
  +
----
==Comments==
 
  +
Also
  +
  +
<pre>
  +
yy@"
  +
</pre>
  +
  +
Explanation:
  +
  +
<pre>
  +
yy yank current line into default register
  +
@" execute default recording
  +
</pre>
  +
  +
----
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)