13

Whenever I copy something (usually with a mouse) from a tmux buffer, and paste it later in ViM, the contents are truncated. Last attempt gave me only about 750bytes of the full block I copied.

This is in iTerm on a Mac.

5
  • 2
    You should probably give some more information. Truncated in what way? From the beginning? From the end? How much is "the full block?" If it's just from the beginning, are you entering insert mode before pasting?
    – Pandu
    Commented Mar 27, 2014 at 20:41
  • 1
    Maybe there is a special character in the copied text that screws up with vim modes. Have you tried toggling paste mode with :set paste in vim before pasting?
    – Aliou
    Commented Mar 27, 2014 at 22:08
  • @pandubear it's being cut off just at the end. Furthermore, this seems more like a tmux thing than a vim thing. Pasting somewhere else has the same issue.
    – Evert
    Commented Mar 28, 2014 at 0:30
  • I've had this issue for a long time (using Tmux, iTerm2) using reattach-to-user-namespace, and I resort to pasting directly from Tmux's buffer as mentioned in an answer below.
    – shashin
    Commented Jun 30, 2014 at 14:32
  • See my answer on this similar question. You need to update your config to use the copy-pipe command to pass the data to pbcopy. superuser.com/a/956451/52396 Commented Aug 13, 2015 at 10:16

5 Answers 5

4

be sure to paste from tmux buffer

I had the same problem, and was getting the paste step wrong. I came across this post.

What I was trying to do was paste from the system clipboard simply using ctrl-v (which worked, but only partially, as you explained in your question).

Instead, pasting from the tmux buffer using ctrl-b ] does the job correctly.

2
  • 1
    This doesn't work, it only prints 2 lines from the selection.
    – weberc2
    Commented Apr 6, 2016 at 15:33
  • As answered below the only reason the system clipboard is truncated is due to a terminal limitation. You can reconfigure your terminal or get the text to the system clipboard using an external utility.
    – Chris Hunt
    Commented May 6, 2018 at 17:33
1

I had the same problem using tmux 1.8, iTerm2, and reattach-to-user-namespace. I ran across a tmux config binding that fixes the problem: it explicitly copies the last buffer selection to the clipboard:

bind-key q run "tmux save-buffer - | reattach-to-user-namespace pbcopy"

Put it in your ~/.tmux.conf, and then C-b q will pull everything into your clipboard after a selection.

1

Problem Solved. A few pointers.

  1. reattach-to-user-namespace is not required. Just pbcopy.
  2. Tested with tmux 2.3
  3. The trick is to get the MouseDragEnd1Pane event to fire off pbcopy.
  4. Use iTerm2 which means that Mouse Support just works. From tmux v2.1 only set-option -g mouse on is required.
  5. You don't need vi-copy mode. Just make sure that the MouseDragEnd1Pane is bound as below

Here is my stripped down ~/.tmux.conf

# --------------------------------
# Turn on the Mouse Support - defaults seem good
# --------------------------------
set-option -g mouse on
# when we finish "selecting" send it to pbcopy (and into the OS X buffer)
bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "pbcopy"

# --------------------------------
# Use vim keybindings in copy mode
# --------------------------------
setw -g mode-keys vi

# Setup 'v' to begin selection as in Vim
# You enter with C-b [ and then "v" - then normal keypresses to "highlight"
# .. [Enter] or "y" will select (because of below bindings)
bind-key -t vi-copy v begin-selection
#
# 'y'ank will send the selection to the OS X buffer
bind-key -t vi-copy y            copy-pipe "pbcopy"

# --------------------------------
# Update default binding of `Enter` to also use Send the selection to OS X buffer
# --------------------------------
unbind   -t vi-copy Enter
bind-key -t vi-copy Enter        copy-pipe "pbcopy"

# selecting can now be done with
#  hilighting with a mouse
#  selecting with C-b [ v .. now vi mode for selecting text
#
# pasting  can now be done with
# ⌘ - V
# C-b ]
0
0

To copy into Vim without mouse you can paste the tmux paste-buffer command output right into the file you are editing.

noremap <leader>p :r !tmux paste-buffer<cr>

Save it in your vimrc.

It maps \+p to paste from buffer.

The <leader> being backslash (\) by default.

But you can change it to any other key (*) you like by setting:

let mapleader="\<Space>"

for instance.


(*) Within Vim's limits, that is.

0

I answered a similar question here. There are a couple of pieces that may be impacting you here:

  1. terminal
  2. tmux settings
  3. OS

If you're trying to paste from the system buffer and getting this behavior then there may be a limitation in your terminal that truncates the size of the data that can be set by tmux. The solution (in tmux 2.6+) is to use something like:

# disable built-in setting of system clipboard
set-option -g set-clipboard off
# use external utility for setting system clipboard
# on Linux - xclip (+ssh display forwarding for remote machines)
# on osx - pbcopy
# on cygwin - cat > /dev/clipboard
# on Windows Subsystem for Linux (WSL) - clip.exe
# copy-pipe-* commands also copy to the tmux clipboard
# y yanks to clipboards but stays in copy mode
bind -T copy-mode-vi y send-keys -X copy-pipe "xclip -in -selection clipboard"
# Remove default handling
unbind -T copy-mode-vi Enter
# Enter yanks to clipboards then exits copy mode
bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard"

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