Scrolling down both parts of a split-window at the same time in Vim
Asked Answered
B

6

160

Is it possible to scroll down the left and right parts of a vertically split window in Vim? I have two files I would like to compare roughly. Each line of these files looks almost the same.

Bracelet answered 7/7, 2009 at 14:31 Comment(0)
G
101

See the documentation for scroll-binding. You'll need to set this for each window that you want bound (e.g. a minimum of 2)

If you're comparing 2 files, however, vimdiff may be of more use

Godric answered 7/7, 2009 at 14:37 Comment(2)
@BrianAgnew Please include the actual code, not just links.Paten
:set scrollbind in each split windowGodric
S
239

Go to the first split, and type in

:set scrollbind

Go to the next one (ctrl+w), and do the same.

To disable:

:set noscrollbind

For more info, check the documentation for scroll binding - http://vimdoc.sourceforge.net/htmldoc/scroll.html#scroll-binding

Snapdragon answered 7/6, 2010 at 3:52 Comment(3)
If you have all the files open, you can also :windo set scrollbind, to set it for all splits at once.Karyotype
it's nuggets like these that make me wonder why we don't teach this stuff in schoolBounce
:set scrollbind! to toggleUnderhung
G
101

See the documentation for scroll-binding. You'll need to set this for each window that you want bound (e.g. a minimum of 2)

If you're comparing 2 files, however, vimdiff may be of more use

Godric answered 7/7, 2009 at 14:37 Comment(2)
@BrianAgnew Please include the actual code, not just links.Paten
:set scrollbind in each split windowGodric
D
64
:windo set scrollbind

will set scrollbind in all windows.

Dysprosium answered 27/8, 2013 at 13:15 Comment(2)
If you find yourself doing this a lot, it might be useful to have something like nmap <F5> :windo set scrollbind!<cr> to toggle scrollbind in all open windows.Aswarm
Don’t know why but scrollbind! did not work for me, but invscrollbind did. A SUPER mapping. Thanks!Loathe
S
16

From the command line:

vim -O file1 file2 -c 'windo set scb!'

-O = open side by side.

-c = what follows in quotes is treated as a vim option.

'windo' = apply to all panels.

'scb' = shorthand for scrollbind. Saves some typing, but the two are interchangeable.

'!' = toggle. This way you can use the same command to turn it off later if you choose to.

Spirt answered 6/7, 2018 at 21:44 Comment(0)
T
12

G'day,

Tried using vimdiff on the two files?

vimdiff file1 file2

This will give you the scroll binding by default.

Tolle answered 7/7, 2009 at 14:39 Comment(2)
the problem is that all the lines differ, it's starting to be a mess.. The lines are nearly the same but may differ by one character...and I don't want my view to be too much disturbed..thanks though.Bracelet
@Bracelet you might consider tweaking your colorscheme, see #24667058Absorbing
R
6

For posterity, here's what I needed to do, since I didn't start with vimdiff.

I loaded one file. Then :vsp to load the other.

They are pretty different files, but I wanted to see what's common in between them.

So...

:set diff
:set diffopt=iwhite
:set scrollbind
Revile answered 22/5, 2014 at 12:13 Comment(1)
You can get all of those for a given buffer (:diff, :diffopt, :scrollbind) in one command with :diffthis in each of the buffersAbsorbing

© 2022 - 2024 — McMap. All rights reserved.