0

Is there a way to similary scroll to simultaneously go to next search instance on all split files? Currently I am using :windo // to search in all splits but pressing "n" only goes to next instance in active split window.

I have 2 different files open in vim split and am looking to jump the the next instance of searched string in both simultaneously.

For context: When we use the vimdiff on 2 similar files, searching for a string and pressing "n" lets us scroll to the next match in all files. Looking for something similar.

rawat89
  • 19
  • 7

1 Answers1

0

When you diff two files, the option :help 'scrollbind' is enabled, which synchronizes the scroll of the two windows. You can run the following command in each window to have the same behavior:

:set scrollbind

or this single command to cover every window:

:windo set scrollbind

Note that it doesn't work the way you described. The non-focused window doesn't exactly scroll to the next match, all it does is scroll in the same direction and by the same amount as the focused window.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • Thanks, this is also helpful to a certain extent since my 2 files are not the same but similar. I wonder if simultaneously scrolling to next match is even supported. – rawat89 Jan 20 '23 at 14:40
  • It's not. It can probably be scripted, though. – romainl Jan 20 '23 at 14:56
  • That would be a great help if someone can point me in the right direction on how to do so. I've tried vimrc scripts before and it was a nightmare to figure it out since I'm mostly proficient with tcl and only a tiny bit of csh. – rawat89 Jan 23 '23 at 06:40