Raimondi / delimitMate

Vim plugin, provides insert mode auto-completion for quotes, parens, brackets, etc.
http://www.vim.org/scripts/script.php?script_id=2754
1.98k stars 117 forks source link

Fix repeat and undo #227

Closed wellle closed 8 years ago

wellle commented 8 years ago

I was often intrigued by plugins that automatically close the delimiters I open, but there was always that one deal breaker: They wouldn't work properly with how Vim handle command repetition and undo.

Now that Vim added a way to let plugins like this move around in insert mode without breaking the undo chain, I thought I might give delimitMate another try. This PR uses that new feature if it's available to not break any insertions when moving left or right within the current line.

Since I'm not familiar with this plugin's code base, please let me know if I forgot some places where we should use the undo join or if I joined in places that shouldn't be joined. Also if the code should be arranged differently, I'm happy to do some cleanup.

For a simple test I typed in a new buffer Ia(b,"c which always leads to the following buffer content: a(b,"c"). Before the patch, pressing u or . would undo to a(b,"") or repeat to a(b,"cc") respectively.

With the PR applied we undo to the empty line or repeat to a(b,"c")a(b,"c") instead. So the full operation is undone or repeated in a single operation, as expected. A Vim version before 7.4.849 is not affected by the patch and behaves as before.

I see you have tests that I believe should be used for this. Maybe someone with more experience with this test setup would be more efficient in setting up those new tests. Otherwise I can take another look and see if I can add some.

Close #138. Related to: #50 #171 #184

Don't break undo sequence when moving in insert mode

Since Vim version 7.4.849 [1] we can move in insert mode without breaking the undo sequence by inserting U before the movement key.

Add s:joinUndo which returns "U" if available. Use s:joinUndo before doing any or movements in insert mode to keep a single undo point which can be repeated and undone with a single command.

[1] https://github.com/vim/vim/releases/tag/v7.4.849

Raimondi commented 8 years ago

Thanks!

blueyed commented 8 years ago

Thanks indeed! Now a lot of us are probably waiting for the patch to be merged by Neovim, if it hasn't been done already?!

Tests for this would indeed be very good!

wamaral commented 8 years ago

:+1: this was bugging me for quite some time now :)

Konfekt commented 8 years ago

Thanks!