2
votes

I would like to have a command in tmux vi-copy mode, which combines the following three steps into one:

  1. selects the current line
  2. copies the selection that was made in step 1
  3. copy-pipes the copied selection to xargs

Could it look like this?

bind-key -t vi-copy o select-line; copy-selection; copy-pipe "xargs -I{} tmux select-pane -t 1"

I got the last part running like this link:

bind -t vi-copy 'y' copy-selection
bind -t vi-copy y copy-pipe "xclip -sel clip -i"
bind -t vi-copy y copy-pipe "xargs -I{} tmux send-keys -t 1 ';call OpenTestFile(\"{}\")' Enter"

If I select something in copy mode with the above, tmux is:

  1. copying the selection
  2. sending the keys: ;call OpenTestFile("SELECTION") to the pane number 1 (I have vim opened there)
  3. switching to that pane

In the vim-function OpenTestFile(input) I realize, that vim extracts a filepath from the tmux-line-selection and opens it for editing.

But I don't want to use the y key, instead I want to use the o key, for doing that and to avoid to having to select the line before.

Update 1

It seems, that it isn't possible to bind multiple commands in a mode. link

2

2 Answers

3
votes

Original tmux doesn't allow to bind more than one command for 'mode' keystrokes.

Luckily, there's a mod for allowing to do that: http://ershov.github.io/tmux/

For example:

bind-key -t vi-copy o tcl { select-line; copy-selection; copy-pipe "xargs -I{} tmux select-pane -t 1" }
0
votes

I have not tested this specific configuration, but in general you should be able to execute multiple commands inside one binding by backslash-escaping the ; separator. You can also backslash-escape newlines, so something like this ought to work (assuming your cited example is working):

bind -t vi-copy y \
    copy-selection \;\
    copy-pipe "xclip -sel clip -i" \;\
    copy-pipe "xargs -I{} tmux send-keys -t 1 ';call OpenTestFile(\"{}\")' Enter"