Ahmed Fasih
Ahmed Fasih

Reputation: 6937

How do I synchronously view and scroll vertically-split buffers in Vim?

I have two vertically-split buffers in Vim showing two separate files that I want both displayed and scrolled synchronously. With :set scrollbind at the top of both buffers, I can get the scrolling part down (so when I hit zt in one buffer, the current line jumps to the top in both buffers), but unfortunately, the display is not synchronized.

What this means is that if the lines in the files are of differing lengths, the two buffers won't be visually aligned. I'd like Vim to display extra line breaks in order to ensure that long wrapped lines do not interfere with the vertically-synchronized display of the two buffers.

Thanks!

Upvotes: 44

Views: 12028

Answers (3)

Benoit
Benoit

Reputation: 79225

I doubt Vim is really appropriate to diff vertically buffers that have very long lines of text if you need to wrap them, and yet, I am a real Vim aficionado.

What I could suggest to you is:

  • With vim, insert line numbers in front of every line, and double-space your files (:g/^/put _). If you are translating, line numbers should not really be subject to changes?
  • Open both files with Kompare or Meld that have graphical tricks to smoothly bind lines of unequal lengths. Then adapt the color scheme to behave like if it was not a diffing tool.

Upvotes: 0

Herbert Sitz
Herbert Sitz

Reputation: 22256

In addition to setting scrollbind in both buffers, you need to issue the command :syncbind . That should sync the scrolling. I don't know if it will do it perfectly if you're wrapping lines and the two files have lines of different lengths. But if you turn wrap off I think it should keep them at same line numbers.

Upvotes: 22

janm
janm

Reputation: 18359

You can use

:set nowrap

To stop the long lines from being wrapped, so that your buffers are synchronised. Not exactly what you asked, but close.

Upvotes: 3

Related Questions