开发者

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-synchronize开发者_JS百科d display of the two buffers.

Thanks!


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.


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.


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜