matze / vim-move

Plugin to move lines and selections up and down
http://www.vim.org/scripts/script.php?script_id=4687
MIT License
1.2k stars 56 forks source link

use :undojoin to merge subsequent moves into one #63

Closed jedrzejboczar closed 2 years ago

jedrzejboczar commented 2 years ago

Closes https://github.com/matze/vim-move/issues/7.

With these changes, after each move operation we store b:changedtick and the move direction. When the function is called again it checks if b:changedtick is still the same. If it didn't change, then :undojoin is called to merge the new change with the old one in undo history. The previous move direction is also compared and :undojoin is used only if it is the same as current move direction.

matze commented 2 years ago

Thanks for the implementation. Works flawlessly for me and I think the functionality is worth merging. However, I am not sure if we should make merging the undos the default behavior. I am certainly used to the way undo works now.

jedrzejboczar commented 2 years ago

Sure, if you think it's better to keep the old behaviour, then it may be disabled by default. I initially set it to enabled as this undo-merging seemed more like the "expected" thing to me, but it may be just personal preference :) And it may be worth to avoid breaking changes. Feel free to modify it as you will or I can update the PR tomorrow if you want.

matze commented 2 years ago

Nah, it's good. I'll change it in my config if I get to confused over time and change the default if too many people complain. Thanks again for the PR!