Reputation: 240
in vim, is there a way i can delete a block of text written by a i(no)remap, or an iab? for example, say i have
inoremap xx \hat{x}
in my .vimrc file, I want to be able to delete \hat{x} with one-two keystrokes (but not ^w or dB .. I could have two consecutive iabs consisting of just text, so I need to be able to cut abababcdcdcd in the middle, if cdcdcd is an iab of, say, "cc")
any ideas?
Upvotes: 5
Views: 485
Reputation: 392893
Finally a clean solution
inoremap xx ^Gu\hat{x}^Gu
(That's C-g there)
No more strange effects. You can even choose whether you want to isolate the undo item at both ends or just at the start (leave the trailing ^Gu
if you don't mind the hat-x being undone together with what came after it)
Now the salvaging info I used was, finally, trivial:
:he undo|/break/;+3p
Output:
To do the opposite, break a change into two undo blocks, in Insert mode use CTRL-G u. This is useful if you want an insert command to be undoable in parts. E.g., for each sentence. |i_CTRL-G_u|
Upvotes: 2
Reputation: 59277
As the undo undoes the last insert, I frequently place a <Esc>a
in the beginning of my mappings.
For example:
inoremap xx <Esc>a\hat{x}
Makes you leave and came back to insert mode so the undo can work properly. If you mistyped it, you can undo correctly.
I know this can be ugly and non-sense, but works. I'd love to know if there is a better solution to "flush" the undo.
Upvotes: 1