Wednesday, September 5, 2012

Re: Diff 2 files with lines added at top of second file: confusing

On 05/09/12 19:29, chroyer@comcast.net wrote:
> Hi,
> I noticed one scenario where vim is not showing me the diff as I expect.
>
> I have 2 files, a.txt and b.txt that for that test (I have seen it on
> "real" files")
> a.txt has 100 lines, each line with just a number. Looks like this
> 0
> 1
> 2
> [...]
>
> b.txt is same as on a, but I added a few lines at the top, all with just
> a -1. Looks like this
> -1
> -1
> -1
> 0
> 1
> 2
> 3
> [...]
>
> If I run gvim -d b.txt a.txt, things are as I expect: I see the added
> block of -1, few common lines, then the rest is folded.
>
> But if I run gvim -d a.txt b.txt, I don't initially see the block of -1.
> The vertical scrollbar is all the way to the top (I can't scroll up),
> the first 6 lines are shown with no diff, the rest is folded. If I just
> scroll with the mouse while on window of file a, nothing happens. Same
> if gg on a. But if click on the window where b is, the scroll bar is not
> partly down, and I can scroll up (or gg) to the top of b and see the diff.
>
> I guess it make sense: by default the active window is for a, and it is
> showing the top of a; but it forces me to click on b and scroll every
> time to make sure that I am not missing diffs. And I have forgotten a
> few times...
>
> Am I the only one to see that? If not, would it be possible to have vim
> automatically scroll to show the top of the first diff block, regardless
> of which window it is in?
>
> I am using gvim 7.3.646, on Windows XP. I have diffopt=filler. I have
> tried other settings, including horizontal diffing, but none helped for
> that particular issue.
>
> I searched around, but no success, sorry.
>
> Thank you.

:help diff.txt (section 1 "Starting diff mode")
[...]

In each of the edited files these options are set:

'diff' on
'scrollbind' on
'cursorbind' on
'scrollopt' includes "hor"
'wrap' off
'foldmethod' "diff"
'foldcolumn' value from 'diffopt', default is 2

These options are set local to the window. When editing another file
they are
reset to the global value.


:help 'scrollbind'
[...]
See also |scroll-binding|. When this option is set, the current
window scrolls as other scrollbind windows (windows that also have
this option set) scroll. This option is useful for viewing the
differences between two versions of a file, see 'diff'.
[...]


:help scroll-binding
5. Scrolling synchronously *scroll-binding*

Occasionally, it is desirable to bind two or more windows together such that
when one window is scrolled, the other windows are also scrolled. In Vim,
windows can be given this behavior by setting the (window-specific)
'scrollbind' option. When a window that has 'scrollbind' set is
scrolled, all
other 'scrollbind' windows are scrolled the same amount, if possible. The
behavior of 'scrollbind' can be modified by the 'scrollopt' option.

When using the scrollbars, the binding only happens when scrolling the
window
with focus (where the cursor is). You can use this to avoid scroll-binding
for a moment without resetting options.

When a window also has the 'diff' option set, the scroll-binding uses the
differences between the two buffers to synchronize the position precisely.
Otherwise the following method is used.

*scrollbind-relative*
Each 'scrollbind' window keeps track of its "relative offset," which can be
thought of as the difference between the current window's vertical scroll
position and the other window's vertical scroll position. When one of the
'scrollbind' windows is asked to vertically scroll past the beginning or end
limit of its text, the window no longer scrolls, but remembers how far past
the limit it wishes to be. The window keeps this information so that it can
maintain the same relative offset, regardless of its being asked to scroll
past its buffer's limits.

However, if a 'scrollbind' window that has a relative offset that is
past its
buffer's limits is given the cursor focus, the other 'scrollbind'
windows must
jump to a location where the current window's relative offset is valid.
This
behavior can be changed by clearing the 'jump' flag from the 'scrollopt'
option.




Best regards,
Tony.
--
Great minds run in great circles.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment