(Reviewed and added autocmd that makes it more useful. None of the comments added anything worth keeping (and the first was even incorrect))
Line 1:
Line 1:
−
{{review}}
{{TipImported
{{TipImported
|id=637
|id=637
Line 20:
Line 19:
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.
−
MosttimesIneedit,ifItypeddd and theline still remains because ofInsert-Modeandtheunwanted'dd'istsomewhere in my text.
+
Thiscanallowyoutoeasilydowhatyouintended when you enter insert mode but change your mind later (and forgetyou're still in insert mode). Unfortunately, it isn't all that useful by itself, because atextinsertioncountsasasingleoperation 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:
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.
created January 17, 2004 · complexity basic · author Jochen Behrens · version 5.7
If you are in insert mode and typed a command for normal mode, you can use it.
inoremap <somekey> <Esc>u@.
This mapping switches to normal mode, undoes the last insertion and takes it as a command.
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 undo sequence. Therefore, it only works if the ONLY text you enter is a normal-mode command.
You can make this mapping more useful by combining it with the following autocmd:
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.