patch 9.1.1473: inconsistent range arg for :diffget/diffput

Problem:  inconsistent range arg for :diffget/diffput
Solution: fix the range specification, place the cursor for :diffput and
          :diffget consistently on the last line (Yee Cheng Chin)

Previously, `:<range>diffget` only allowed using 1 or above in the range
value, making it impossible to use the command for a diff block at the
beginning of the file. Fix the range specification so the user can now
use 0 to specify the space before the first line. This allows
`:0,$+1diffget` to work to retrieve all the changes from the other file
instead of missing the first diff block. Also do this for `:diffput`.

Also, make `:diffput` work more similar to `:diffget`. Make it so that
if the cursor is on the last line and a new line is inserted in the
other file, doing `:diffput` will select that diff block below the line,
just like `:diffget` would.

Also clean up the logic a little bit for edge cases and for handling
line matched diff blocks better.

closes: #17579

Signed-off-by: Yee Cheng Chin <ychin.git@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yee Cheng Chin
2025-06-20 18:44:18 +02:00
committed by Christian Brabandt
parent 476b65ebac
commit d75ab0cbf5
6 changed files with 82 additions and 17 deletions

View File

@ -1,4 +1,4 @@
*diff.txt* For Vim version 9.1. Last change: 2025 Mar 28
*diff.txt* For Vim version 9.1. Last change: 2025 Jun 20
VIM REFERENCE MANUAL by Bram Moolenaar
@ -304,18 +304,20 @@ that the buffers will be equal within the specified range.
When no [range] is given, the diff at the cursor position or just above it is
affected. When [range] is used, Vim tries to only put or get the specified
lines. When there are deleted lines, this may not always be possible.
affected. There can be deleted lines below the last line of the buffer. When
the cursor is on the last line in the buffer and there is no diff above this
line, and no [range] is given, the diff below the cursor position will be used
instead.
There can be deleted lines below the last line of the buffer. When the cursor
is on the last line in the buffer and there is no diff above this line, the
":diffget" and "do" commands will obtain lines from the other buffer.
When [range] is used, Vim tries to only put or get the specified lines. When
there are deleted lines, they will be used if they are between the lines
specified by [range].
To be able to get those lines from another buffer in a [range] it's allowed to
use the last line number plus one. This command gets all diffs from the other
buffer: >
To be able to put or get those lines to/from another buffer in a [range] it's
allowed to use 0 and the last line number plus one. This command gets all
diffs from the other buffer: >
:1,$+1diffget
:0,$+1diffget
Note that deleted lines are displayed, but not counted as text lines. You
can't move the cursor into them. To fill the deleted lines with the lines