I'd like to experiment one of the tip by Drew Neil in his Vimcast, that is to "escape" regularly, so that it gives more granularity to the "undo" command.
For example, I write one short sentence. Then I press Escape. Then I press a to continue my editting and write another sentence. So when I press my final escape, I can press u several times and only one sentence at a time will disappear, not the whole text.
I was wondering if I could remap this simple sequence, (for example with kj
):
inoremap kj <esc>a
The key remapping works (it feels like I didn't exit insert mode), but the problem is, when I use kj
to mark a pause after a sentence, then if I write another sentence and press escape, then pressing u will erease my two sentences at once, and therefore I don't benefit the granularity I was looking for in the first place.
Why is it pressing kj
doesn't have the same effect on the undo command compared to pressing manually escape + a ?
And, is there a way to do the remaping with the desired effect?
ctrl-g u
in insert mode already do what you want?inoremap kj <c-g>u
is working with the undo command too, that's great. Thank you so much! I can accept this answer if you may add it. I have no idea, whatctrl-g
means in insert mode, it seemsctrl-g
+k
andctrl-g
+j
go up and down one line while breaking the undo tree.