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

More improvements to the MoveHorizontally functions #48

Closed hugomg closed 4 years ago

hugomg commented 4 years ago

I gave another close look at the MoveHorizontally functions. Found a couple of bugs to fix and figured out a way to put the movement logic in a single place. That are three main changes in this PR:

1) Improved the workaround for the problem of virtualedit putting the cursor in the wrong place. Instead of fixing the cursor after virtualedit messes up its position, we now disable virtualedit in the cases it is bugged. This means that the [ and ] always point to the correct place and can now be used by our functions. I also reported the bug to the Vim maintainers. They quickly found out what was the problem and already have patches queued up for the next Vim release.

2) The core movement logic MoveCharHorizontally and MoveBlockHorizontally in now in a single function. The trick is that "x" does the same thing as "d" if we are in Visual mode.

3) Uses of virtcol() are replaced by col(), improving how the functions behave in the presence of tabs. See the last commit message for details.

matze commented 4 years ago

Alright, thanks :+1:

hugomg commented 4 years ago

My pleasure :)