Vim – How to Scroll Large Datafile While Keeping Header

lesspagerscrollingvim

Suppose I have some large datafile, which overflow the screen in both vertical and horizontal direction. How can I browse this file, while the header-lines stay on the screen?

For the moment, I am using less -S, so that I can nicely scroll my file horizontally and vertically. However, when scrolling down, the header lines obviously disappear. Is there a way to keep these using less?

An alternative is using vim in split-screen mode with :set nowrap. However, now if I scroll horizontally, the top window doesn't scroll in the same way (:windo set scrollbind only works for vertical scrolling as far as I know).

Best Answer

If you're familiar with vim, this is probably the best option for you. You can enable horizontal-scroll-bind-only by changing 'scrollopt':

set scrollopt=hor

So with vim -u NONE, you get the desired behavior with:

:set scrollopt=hor
:set nowrap
:1split
:windo set scrollbind

You may want to adjust 'sidescroll' and 'sidescrolloff' to change how many columns are skipped and how far from the edge skipping starts respectively.

Related Question