Could I just duplicate what scrollbind does, and use tmux to send-keys to the other vim?

I have vim on an android device (in termux), and want the effect of spreading vim over another device's display, by scrollbinding with an offset. i.e. as text scrolls off the top of one, it scrolls onto the bottom of the other. In effect, a single terminal twice as high.

BTW client-server isn't available to me (on android, no MS or xwindows; not compiled on my vim executable anyway)

  • 1
    Bummer, I would have suggested something using client-server feature. Why don't you pursue the send-keys idea?
    – B Layer
    Jul 2, 2018 at 3:47
  • @BLayer Thanks for the interest/encouragement! I'm thinking I could map hjkl (and arrows) to also send-keys. But it would be nice to see how vim does it with scrollbind. 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? Jul 3, 2018 at 7:43
  • @BLayer Looks like scrollbind is done in c and not scriptable. I can get called on a cursor event with CursorMoved autocmd-event, which would intercept most (not all) scroll movements. I can get the line at the top of the window with line("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 call tmux when it changes (i.e. scrolls). Jul 3, 2018 at 9:42

1 Answer 1



:autocmd CursorMoved * silent exe '!tmux send-keys Escape :' line("w0")-16: 'Enter' 'z Enter'

  1. hook into CursorMoved events (vim lacks scroll events; we could map explicit scrolls commands, like C-e, C-y)

  2. get the line at the top of the window line("w0")

  3. 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.


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.

  • +1 for getting something working at all. Not a trivial problem. (Sorry I didn't have any input....busy then vacation.) Small improvement: send control-u right before line("w0") to make sure the command line is cleared (think of : when in Visual mode)
    – B Layer
    Jul 7, 2018 at 2:53
  • I'm confused by something....both devices are using tmux? Locally? Can you ssh one of them to the other (or both to a third system) so you can use a shared tmux session thereby avoiding the hoop jumping?
    – B Layer
    Jul 7, 2018 at 2:58
  • @BLayer I'm not sure what you mean... I'm sshing from one to the other now. Both have termux (terminal emulator), tmux, ssh and vim.When I set it up, I actually sshed into the first machine, and started tmux from there, and then attached to it on the first machine (i.e. opposite of my answer). A variation is to use a tmux "group" session - this has the same windows, but which one is active is controlled by the client, so you can view a different tmux window on each device. By attaching to the same tmux session you can control the other display from the first device. Jul 7, 2018 at 3:18
  • @BLayer No problem - without your initial encouragement, I might not have got it working at all! I didn't know about control-u, but actually I'd like to avoid using the : line altogether... I think a vim function would do this? BTW android Instant Apps was auto-updating over the (low-bandwidth) bluetooth tethering, so that may be why the layency was so high. In my link, a shared tmux ssh vim session shared over bluetooth had mostly imperceptible latency. BTW Setting this all up is a bit of an ordeal, but next time I'll try chained rubber bands to stablize the phones. Jul 7, 2018 at 3:27
  • @BLayer Wait, I think you mean try to do as muchof the setup as possible from the first device (to avoid switching). I think the minimum on the second device is: ssh (so it's displayed there); and tmux (either to start the session, or attach to it). Is there another way? It's tricky to automate because of this, but I guess I could automate some: a script on each machine. Jul 7, 2018 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.