Reputation: 5398
Is it possible in Vim to lock the top line of a window so that the first line in buffer is always seen on top of the window?
I have a file, say, dump of a database table. On the first line there are names of columns, other lines contain data. I want to be able to scroll contents up and down, and always see column names.
N.B. Lines can be lengthy, so I use nowrap
and want column names and contents to scroll right and left simultaneously. That's why :1split
doesn't suit -- unless there's a way to scroll two windows at the same time.
Thanks.
Upvotes: 10
Views: 3992
Reputation: 1
Attempted to automate it with a script in "<leader>fr"
https://github.com/PxCxio/vim-freeze-row/tree/master/doc
Did a version for nvim seems to be working smoothly
Upvotes: 0
Reputation: 1654
Thanks guys! Let me summarize the actual commands that did the job for me:
:1spl # create an extra window with only 1 line
:set scrollbind # synchronize upper window
ctr+W , arrowDown # switch to other window
:set scrollbind # synchronize lower window
:set sbo=hor # synchronize horizontally
Upvotes: 6
Reputation: 1018
Split your window, decrease the top window height, set the top most line to be the first one and get back to the working window.
:split
:resize 1
gg
Ctrl-w w
Upvotes: 3
Reputation: 272397
You can scroll two windows at the same time, so I think you can do what you want by splitting your window, and locking the scrolling behaviour. See :scrollbind and this tip for more details. Note that you have to lock each window in order that they move in sync.
Upvotes: 2