Hack-of-concept:
:autocmd CursorMoved * silent exe '!tmux send-keys Escape :' line("w0")-16: 'Enter' 'z Enter'
hook into CursorMoved
events (vim lacks scroll events; we could map
explicit scrolls commands, like C-e
, C-y
)
get the line at the top of the window line("w0")
tell vim in the tmux session to move one screen higher than that (-16
), by putting the cursor there (Escape :n Enter
, where n
is the line, and tmux accepts special keys by their names, Escape
, Enter
), then scrolling to put the cursor at the top of the screen (z Enter
)
To use this, edit a file in one window - this is where you control it from. In second window, start tmux, then edit the same file (readonly). Enter the above autocmd
in the first window. You can check that vim in the second window is now "remote scrollbound" to the first window.
Now, on the other phone, ssh into the first phone, and attach to the tmux session. You will get a duplicate of the second window above. Place this phone above the other phone. BTW here's how I connected androids over bluetooth, which had lower latency for me.
Results
It works.
There's 250ms latency or so before the other window scrolls, but it's OK.
There are practical problems, putting one smartphone above another in a secure way. It's important for usability to have the screens at the same angle, to avoid glare from ceiling lights. If the screens are different dimensions, the text won't line up.
client-server
feature. Why don't you pursue thesend-keys
idea?hjkl
(and arrows) to alsosend-keys
. But it would be nice to see how vim does it withscrollbind
. Maybe it uses hooks to intercept the actual scrolling itself, instead of the keys that cause scrolling? So that other movements e.g. page up/down, from search etc also work. There's also the wrinkle of maintaining a relative-offset even at top/bottom of a file. Any idea where I'd find vim's implementation?c
and not scriptable. I can get called on a cursor event withCursorMoved
autocmd-event
, which would intercept most (not all) scroll movements. I can get the line at the top of the window withline("w0")
(and set it with:number
, choosing some offset). Performance: to avoid slowing down the cursor, I could store the last top-line-of-window and only calltmux
when it changes (i.e. scrolls).