6

I'm using tmux with WSL (Ubuntu 18.04) and I can't figure out how to paste into tmux. Pasting works great with the normal terminal by simply right clicking, but this doesn't work in tmux.

All the tutorials online seem to explain how to copy text from tmux to system clipboard which I have working through tmux-yank, but no luck for system clipboard to tmux.

Edit: it seems like this works for most people by default. What information can I provide that would be most helpful to debug?

Update: I realized that right-click currently lets me move the bar that separates my two vertical tabs. I didn't set this behavior anywhere, where could this be coming from? Here is my tmux conf which I got online:

# Set a new prefix / leader key.
set -g prefix M-j
bind M-j send-prefix

# Allow opening multiple terminals to view the same session at different sizes.
setw -g aggressive-resize on

# Remove delay when switching between Vim modes.
set -sg escape-time 10

# Allow Vim's FocusGained to work when your terminal gains focus.
#   Requires Vim plugin: https://github.com/tmux-plugins/vim-tmux-focus-events
set -g focus-events on

# Add a bit more scroll history in the buffer.
set -g history-limit 50000

# Enable color support inside of tmux.
set -g default-terminal "screen-256color"

# Ensure window titles get renamed automatically.
setw -g automatic-rename

# Ensure window index numbers get reordered on delete.
set-option -g renumber-windows on

# Start windows and panes index at 1, not 0.
set -g base-index 1
setw -g pane-base-index 1

# Enable full mouse support.
set -g mouse on

# Status bar optimized for Gruvbox.
set -g status-fg colour244
set -g status-bg default
set -g status-left ''
set -g status-right-length 0
#set -g status-right-length 20
#set -g status-right '%a %Y-%m-%d %H:%M'

set -g pane-border-fg default
set -g pane-border-bg default
set -g pane-active-border-fg colour250
set -g pane-active-border-bg default

set-window-option -g window-status-current-attr bold
set-window-option -g window-status-current-fg colour223

# -----------------------------------------------------------------------------
# Key bindings
# -----------------------------------------------------------------------------

# Unbind default keys
unbind C-b
unbind '"'
unbind %

# Reload the tmux config.
bind-key r source-file ~/.tmux.conf

# Split panes.
bind-key h split-window -v
bind-key v split-window -h

# Move around panes with ALT + arrow keys.
bind-key -n M-Up select-pane -U
bind-key -n M-Left select-pane -L
bind-key -n M-Down select-pane -D
bind-key -n M-Right select-pane -R

# -----------------------------------------------------------------------------
# Plugin Manager - https://github.com/tmux-plugins/tpm
# In order to use the plugins below you need to install TPM and the plugins.
#   Step 1) git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
#   Step 2) Reload tmux if it's already started with `r
#   Step 3) Launch tmux and hit `I (capital i) to fetch any plugins
# -----------------------------------------------------------------------------

#bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -in -selection clipboard'
#`bind -t vi-copy y copy-pipe "xclip -sel clip -i"

# List of plugins.
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-yank'

# Initialize TPM (keep this line at the very bottom of your tmux.conf).
run -b '~/.tmux/plugins/tpm/tpm'
6
  • On my system, the right mouse button pastes just fine. I can't find any option I've set specifically to enable that, perhaps you have advertently disabled it. Feel free too look around in my .dotfiles to see if you can find any meaningfull difference. Apr 9 '20 at 5:38
  • I don't know WSL at all but I use Shift+Ins in Linux and in Windows instead of Ctrl+V (which has different meaning in *nix terminal). Please confirm Shift+Ins does not work for you. Apr 9 '20 at 18:55
  • Shit+Ins does not work for me unfortunately Apr 16 '20 at 3:34
  • I wonder if this could be a command prompt problem since WSL is technically launched from cmd. Do you have "Quick Edit Mode" enabled in the properties?
    – aman207
    Apr 16 '20 at 12:40
  • I do have "Quick Edit Mode" enabled, and toggling it doesn't help. Note copy paste does work on right click for regular wsl just not in tmux Apr 16 '20 at 19:00
9

This post solved it.

Holding 'Shift' will bring back OS-default behavior which then lets me copy with select + right-click and paste with right-click.

2

There are several key combinations that usually work on various systems, programs, terminals, etc. And they can be modified with keybindings, whose syntax and capabilities vary widely across shells, programs, etc.

I do not have WSL to try, but you could check these

Ctrl + Shift + Ins
Shift + Ins
Ctrl + Shift + V
Shift + V
1
  • 1
    None of those work, Ctrl + Shift + Ins and Shift + Ins weirdly produce "6~" and "2~" respectively. Apr 16 '20 at 18:56
0

Normally, you have mouse set to on in tmux, then tmux will handle all mouse events instead of the terminal. In most terminals you can press Shift or some other modifier to bypass this and have the terminal take its normal mouse action, you might see if you terminal has a way to do this.

Alternatively, you can bind right-click to paste tmux's top paste buffer with, for example:

bind -n MouseDown3Pane paste-buffer

But this will paste tmux's top paste buffer not the system clipboard.

2
  • That's interesting but still not what i'm looking for. I'm looking to copy from the system (e.g. notepad) and paste into tmux. Apr 9 '20 at 18:41
  • You need to figure out if there is a key to bypass the application mouse (it is usually Shift). Or turn the mouse option off in tmux. Other possibilites are to use refresh-client -l to read the clipboard into tmux, if the terminal supports the OSC 52 escape sequence. Or perhaps use a program like xclip or xsel to get it. Apr 10 '20 at 5:11
0

I've never used Tmux, but atleast with bash and most linux Distros I've used.

Linux terminal: Shift+ctrl+v, rightclick

I'm including VIM because you have VIM tagged in your question. Vim: p

0

A method is described in the article Getting Copy / Paste to Work in WSL with tmux and Terminal Vim.

This uses the open-source project VcXsrv Windows X Server, described as:

Windows X-server based on the xorg git sources (like xming or cygwin's xwin), but compiled with Visual C++ 2012 Express Edition.

The article contains a video tutorial, worth listening to, where the most relevant parts are perhaps at:

  • 12:35 – Setting up VcXsrv to link your WSL and Windows clipboard
  • 15:06 – Getting VcXsrv to start when Windows boots up
0

My configuration, modified from this answer to a similar question:

bind -T root MouseDown3Pane run "/mnt/c/cygwin64/bin/cat.exe /dev/clipboard | tmux load-buffer -; tmux paste-buffer"

Note that requires Cygwin to be installed. If you don't have Cygwin, you can replace the part before the pipe with powershell.exe -c Get-Clipboard, but it will be much slower. Compared to the other answers, this one actually pastes the system clipboard without any workarounds.

-1

I'm using temux all the time, adding this to my .tmux.conf enables me to copy and past without installing an X server :)

#to be able to use mouse buttons and scroll:
set -g mouse on

#to copy to Windows clipboard by marking text
bind-key -T copy-mode-vi MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel clip.exe

#to be able to paste by right clicking (like in default Windows Terminal)
unbind-key MouseDown3Pane
bind-key -n MouseDown3Pane run "tmux set-buffer \"$(powershell.exe -command Get-Clipboard)\"
1
  • 1
    Welcome to Super User! Please do not post the same answer to multiple questions. If the same information really answers both questions, then one question (usually the newer one) should be closed as a duplicate of the other. You can indicate this by voting to close it as a duplicate or, if you don't have enough reputation for that, raise a flag to indicate that it's a duplicate. Otherwise tailor your answer to this question and don't just paste the same answer in multiple places.
    – DavidPostill
    Aug 27 '20 at 16:09

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.