Search code examples
vimfold

How to hide next n lines from the current line interactively


I have a two large tables in a single text file, one below the other. I want to compare them manually line by line.

Each table is very big and I need to scroll a lot. In Vim, can I hide the next N lines from the current line interactively, so that both the lines which I need to compare can be seen on a single screen, and as I move the cursor to the next line, the next N lines should get folded.

In short I want to drag the fold up and down.


Solution

  • Hiding lines is the wrong tool for the job. You want scroll binding (:help scroll-binding).

    :e file.txt
    :set scb
    :vsp file.txt
    :201
    :set scb
    

    This sequence will allow you to open your file.txt in two windows, scroll-bound, with 200 lines apart. If you want to split windows horisontally, replace :vsp with :sp. If you want to adjust the offset, either use the mouse scroll on the non-active window, or turn off scroll-binding in one window, adjust cursor, then reactivate scroll-binding:

    :set noscb
    20j
    :set scb