Question

I have modified the IMAP function from vim-latex, so that an undo is possible, by changing the final return line of LookupCharacter to

return a:char . "^Gu\<bs>" . bs . IMAP_PutTextWithMovement(rhs, phs, phe)

Now to do the undo directly from insert mode, I have this mapping in my .vimrc:

imap <Undo> <Esc>ui

I use the Neo2 keyboard layout, so there's an undo key on the 4th layer.

Now this works fairly well, but the problem is that when I use it at the end of a line, the cursor is placed before the last character. To test it without vim-latex, you could do

:imap a a^Gu\<bs>test

type 'b' in the middle and at the end of a line and then execute the undo, by shortcut or by manually pressing <Esc>ui.

So is there a way to make vim jump back to the correct cursor position?

I have seen an entry in wikia which gives an idea, but I don't know how to achieve it with the imap mapping.

Was it helpful?

Solution

The cursor move is due to the indiscriminate use of i at the end of your mapping. Typically, one temporarily executes a normal mode command via

imap <Undo> <C-\><C-o>u

But in your case, as the undo modifies the buffer, this may not work under all circumstances.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top