Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: How to scrollbind the cursor line too?

Tags:

vim

Two windows in a split windows view of Vim can be bound to each other for scrolling by setting :set scrollbind for both of them. After this is done, if I scroll down the cursor in one windows, the other windows scrolls down along with it.

But, the cursors in the two windows are not bound to each other. I have used :set cursorline to highlight the current line on which the cursor is present. How do I make the highlighted cursorline to scroll simultaneously in the other window too?

like image 374
Ashwin Nanjappa Avatar asked Mar 08 '11 03:03

Ashwin Nanjappa


2 Answers

I don't use this myself, and I may be missing the point, but

:set cursorbind

seems to do exactly what you want.

like image 112
Prince Goulash Avatar answered Sep 21 '22 17:09

Prince Goulash


I just encountered the same situation (with only two windows to compare), and what I did was:

:set cursorbind
:set scrollbind
:set cursorline

and then

:map <Down> j<C-w><C-w><C-w><C-w>
:map <Up> k<C-w><C-w><C-w><C-w>

This causes every press on the up or down arrows to switch back and forth between the windows once, which updates the cursor position on the other window (You can :redraw!<CR> instead of the ugly window switching but that looks bad when moving too fast). Of course, there are many ways to move between lines without the arrows, so this is far from perfect.

However, since this is not a main mode of work for me, useful primarily for comparing files on which diff is too complicated to look at for whatever reason, I find this setting to be practically good enough.

like image 44
Vittore Presto Avatar answered Sep 19 '22 17:09

Vittore Presto