11
votes

I love Tmux and its copy mode with Vi commands, but I'm really annoyed by the fact that this mode is very far from being as efficient as real Vim.

For example, there is no keybinding to just copy a word (yw), I must always "go to the beginning of a word" "begin selection", "go to the end of the word" then "finish selection". A lot of operations when I just need to do yw in vim.

I searched a way to create my own "yw" command in Tmux copy mode. Chaining all the operations needed is a good idea, but a simple bind with commands separated by ; just doesn't work (similar thing works in non-copy mode). Is there something I miss? Or is the copy mode of Tmux just limited and not as scriptable as I need it to be?

4
What did you call to 'bind-key' look like?chepner
Something like : bind-key -t vi-copy X previous-word \; begin-selection \; next-word \; copy-selectionJooj

4 Answers

4
votes

I have this in my tmux conf:

# vi-style controls in copy mode
set-option -g status-keys vi
set-window-option -g mode-keys vi

# v and y like vi in copy-mode
bind-key -t vi-copy 'v' begin-selection
bind-key -t vi-copy 'y' copy-selection

Now after going copy-mode i can easily select words by:

vw

And copy with

y

In tmux you have to select something to copy. There is nothing like copying in normal mode as you know from usual vi/vim commands. Unfortunately you can only use one key (like v or y) for every tmux argument.

You can find more about tmux's vi movement commands here: https://superuser.com/a/197272/57890

4
votes

This appears to be a bug in the bind-key command when called with the -t option. I have filed a bug report at https://sourceforge.net/tracker/?func=detail&aid=3533562&group_id=200378&atid=973262.

3
votes

On upstream (2.4+) tmux version this got changed, in order to create a bindings for begin selection you need to use -T and send-keys with -X.

More info in tmux changelog.

Here my bindings for vi copy mode as an example:

# Bind `v` to trigger selection    
bind-key -T copy-mode-vi v send-keys -X begin-selection

# Bind `y` to yank current selection
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel

# Rebind `mouse click + drag button release` to not jump away from context
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-selection

If you are using emacs copy mode, replacing copy-mode-vi with copy-mode should be enough.

0
votes

There's a patch for tmux allowing to create procedures and bind any number of actions for 'mode' keystrokes: http://ershov.github.io/tmux/