
vim-style yanking in tmux
I like vim quite a bit and I’ve been pleased to be able to set-option -g mode-keys vi
in tmux and gain a conveniently navigable and searchable
scrollback buffer to my terminals.
But sometimes you also want a grab a word or aline from your scrollback and use it on a new command line, so I found myself missing vim “yank” commands.
However, tmux doesn’t natively support multi-key bindings. So one can’t direclty create these mappings:
bind-key -T copy-mode-vi 'yy' send-keys -X copy-line-and-cancel
Fortunately, tmux allows defining (and switching) between “key-tables”. And defining a new key table allows us to model yanking keybindings as a switch to a “yank” mode, like so:
bind-key -T copy-mode-vi 'y' if-shell '#{?selection_present,true,false}' {
send-keys -X copy-selection-and-cancel
} {
switch-client -T copy-mode-vi-yank
}
bind-key -T copy-mode-vi-yank 'y' send-keys -X copy-line-and-cancel
bind-key -T copy-mode-vi-yank 'w' {
send-keys -X select-word
send-keys -X copy-selection-and-cancel
}
bind-key -T copy-mode-vi-yank 'W' {
send-keys lBvE
send-keys -X copy-selection-and-cancel
}
The yw
binding I have is more like yaw
, but that’s what I want in copy-mode
anwyway.
bonus: llm test question
Asking LLMs to come up with this has been a test I’ve been using to evaluate if a model can solve non-trivial problems that require some amount of hacking around for a solution.
All the big LLMs know enough of both vim and tmux and their configs to be able to confidently propose detailed solutions. But apparently it’s a sufficently obscure problem and presents sufficently many subtle limitations that most LLMs really struggle putting it all the together correctly.
Though with the more recent reasoning updates (at least ChatGPT, Gemini and DeepSeek have reasoning variants now) some of the models have been able to either figure it out or at least make progress towards a solution with a bit of back and forth. That makes me optimistic that we might still be on a short path to automating software engineers. But we’ll see.