Welcome to the Power Users community on Codidact!
Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.
Vim horizontal scrollbind skips first scroll if it's the very first interaction
I have a custom spreadsheet viewer in Vim that splits the headers into a top pane and the rest into a bottom pane. I bind horizontal scrolling so that scrolling right keeps the headers above the content.
The problem is that if the very first thing I do is scroll to the right, the header in the top pane doesn't come with it. Subsequent scroll commands line the headers up again. Even a second scroll right. Moving the cursor doesn't line them back up. But if I move the cursor before the first scroll right, the scrollbind works right away.
" :HeadPager
" Turn vim into a pager with a header row
" Adapted from https://unix.stackexchange.com/a/27840/143088
function! HeadPager()
set noswapfile
set nocompatible
set nowrap
set scrollopt=hor
set scrollbind
" Delete/copy header lines
silent 1,2delete
" Split screen with new 1-line buffer (opens at top)
1new
" Switch to top split to paste header
wincmd k
put!
goto
" Switch back to bottom split
wincmd j
" Arrows do scrolling instead of moving
nmap <silent> <Up> 3<c-Y>
nmap <silent> <Down> 3<c-E>
nmap <silent> <Left> zH
nmap <silent> <Right> zL
nmap <Space> <PageDown>
endfun
command! -nargs=0 HeadPager call HeadPager()
I have elided some syntax highlighting, status bar text, and ignoring buffer changes to the file.
vim the_table.txt -u None -s the_pager.vim -c HeadPager
- Why doesn't my first right-scroll bring the top pane along with it?
- Why would it start working after the first scroll?
-
How can I lock them from the very beginning?- Adding a
normal h
afterwincmd j
is enough to be the "first" interaction.
- Adding a
0 comment threads