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.21k stars 56 forks source link

Make vertical moves with large counts move to the first or last line. #44

Closed hugomg closed 4 years ago

hugomg commented 4 years ago

While working on my last PR I noticed that sometimes we would get an error if we tried to make a large vertical move, when the count was large enough to send the lines "out of bounds".

When moving a lines, if it was only slightly out of bounds (1 too much) then it would move the line to the end of the file. The main situation where this happens is if we move the last line down by one -- it stays in the same place without giving an error. It also did not give an error if you tried to move the penultimate line down by two -- it would move it down by one, so it became the last line in the file. However, if you try to move the last line down by 2+ or the penultimate line by 3+ it would give an error E16: Invalid Range.

Moving blocks vertically had a similar problem. If the block was at the end of the file and we tried to move down by one it would also do nothing. But if we tried do move the penultimate line by 2 or by 3+ it would not move it at all.

This commit updates the behavior to be more consistent. Large vertical moves now move the line/block to the first or last line of the file, without throwing any errors.

hugomg commented 4 years ago

Now that I look at it, I think that the problem with the "range" functions that I found was the same one that was discussed in PR #27.

matze commented 4 years ago

Sounds good to me :+1: