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.
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.
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.
Problem Solved. A few pointers.
reattach-to-user-namespace
is not required. Just pbcopy
.tmux 2.3
MouseDragEnd1Pane
event to fire off pbcopy
.iTerm2
which means that Mouse Support just works.
From tmux v2.1
only set-option -g mouse on
is required.MouseDragEnd1Pane
is bound as belowHere 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 ]
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 tmux 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.
I answered a similar question here. There are a couple of pieces that may be impacting you here:
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"
paste
mode with:set paste
in vim before pasting?