1

I am new at using Tmux. I have seen that it is quite difficult to copy-paste inside Tmux. So I searched for an easier method. Some sites suggested that I should use vim mode as I am quite familiar with vim. But, vim mode copy-paste isn't working. I don't know what I am doing wrong. This is my ~/.tmux.conf file.

# Improve colors
set -g default-terminal 'screen-256color'

# Set scrollback buffer to 10000
set -g history-limit 10000

# Customize the status line
set -g status-fg  green
set -g status-bg  black

set -g mouse on

bind P paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'

# remap prefix to Control + a
set -g prefix M-a
# bind 'C-a C-a' to type 'C-a'
bind M-a send-prefix
unbind C-b



# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'

set -g @plugin 'jimeh/tmux-themepack'

set -g @themepack 'powerline/block/blue'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b '~/.tmux/plugins/tpm/tpm'

I am using Tmux 2.5. Thanks in advance for help.

2
  • Make sure to have setw -g mode-keys vi in your conf file

  • As you can see your yanking (which is also sent to the clipboard) is using an external command: xclip. Therefore, make sure to have xclip installed or install it with this script for example.

  • Make sure to enter copy mode with C-b [, then v to begin selection, then y to yank, finally C-b ] to quit copy mode.

  • Not sure if this makes a difference but you can try:

     bind-key -T copy-mode-vi 'v' send -X begin-selection
     bind-key -T copy-mode-vi 'r' send -X rectangle-toggle
     bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel
    

You can also make your .tmux.conf more transportable between versions by catching the tmux version in a variable and using some if statements. I personally have the following .tmux.conf which worked well so far for different versions (never used 2.5 though), I have also stitched this from different sources so I am not 100% sure that the version conditions are really true for every versions:

#check version and put in variable
run-shell 'tmux setenv -g TMUX_VERSION $(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'

setw -g mode-keys vi
if-shell -b '[ "$(echo "$TMUX_VERSION < 2.4" | bc)" = 1 ]' " \
  bind-key -t vi-copy v begin-selection; \
  bind-key -t vi-copy r rectangle-toggle; \
  bind-key -t vi-copy y copy-pipe 'xclip -selection clipboard -in'"

#You would have to adapt here by changing ">" to ">="
#and maybe changing the key binding by what you
#already have if what you have indeed worked after 
#checking the points I gave you earlier.
if-shell -b '[ "$(echo "$TMUX_VERSION > 2.5" | bc)" = 1 ]' " \
  bind-key -T copy-mode-vi 'v' send -X begin-selection; \
  bind-key -T copy-mode-vi 'r' send -X rectangle-toggle; \
  bind-key -T copy-mode-vi 'y' send -X copy-pipe-and-cancel 'xclip -selection clipboard -in'"

It would probably help everyone if someone could check/share a fully portable .tmux.conf for vim like copy/paste with xclip support.

4
  • I have xclip installed. and I have used quotation signs too. but that doesn't work either. Tmux is using Ctrl-Space for selection and Alt-w or Ctrl-w for copying. – Merajul Arefin Pial Jul 6 '20 at 10:25
  • Did you also try to use just "send" instead of "send-keys" ? The last thing I see you could try would be: tmux source-file ~/.tmux.conf to make sure you are indeed using the good configuration file and to put the vim key binding setups after the load of your plugins to make sure this is not overwritten (you could also try even without the plugins to check if the problem comes from there) – jeremy Jul 6 '20 at 12:22
  • Make sure to have setw -g mode-keys vi also before everything else – jeremy Jul 6 '20 at 12:36
  • Thanks @jeremy. The last option worked. – Merajul Arefin Pial Jul 6 '20 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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