I have two windows open in tmux(version 2.3). In first tmux window I have a SSH session to server1 and in second tmux window I have a SSH session to server2. In server1 I opened a shell script with vim script.sh and selected a part of the script with mouse and paste it to vim open in server2 with middle mouse button. This caused lot of trailing spaces for each line:

However, when I open script.sh in server1 with vim -u NONE script.sh(or with cat script.sh or less script.sh) and select the same text area and past it to vim in server2, then trailing spaces are not added:

This made me think that something in my .vimrc causes this behavior. My .vimrc is following:

set relativenumber
set number
syntax on
set hls
set background=dark
set hidden
set listchars=tab:▸\ ,eol:↲,trail:·
highlight NonText guifg=#054a59
highlight SpecialKey guifg=#4a4a59
set noexpandtab
set shiftwidth=4
set tabstop=4
set softtabstop=4
set colorcolumn=81
  filetype on
  filetype plugin on
  filetype indent on
  autocmd FileType cpp setlocal ts=8 sts=8 sw=8 noexpandtab
  autocmd FileType * set formatoptions-=c formatoptions-=r formatoptions-=o
  autocmd BufNewFile,BufReadPost *.bash set filetype=sh

I tried to turn every possible option off(for example set syntax=, set hidden!, set colorcolumn=, etc), but this did not help.

I know that copying and pasting from terminal screen is not reliable, but is there some clever workaround for this?

  • vim -u NONE also takes out plugins. So if it's not in your vimrc there could be a plugin causing it.
    – Tumbler41
    Dec 12, 2016 at 17:11
  • @Tumbler41 I'm not sure it is because of plugins because if I start vim in server1 with vim --noplugin script.sh(skips loading plugins, but settings in .vimrc are loaded), execute :set relativenumber! and :set number! and copy tect to vim in server2, then trailing spaces are added.
    – Martin
    Dec 12, 2016 at 18:51

2 Answers 2


This behavior was caused by colorcolumn option. I started to use quoteplus register.


If you are running it on xterm - one workaround is to use its option to trim trailing spaces from everything you copy with the mouse:

xterm -xrm 'XTerm*trimSelection: true'
  • Welcome to Vi and Vim!
    – D. Ben Knoble
    Feb 13, 2021 at 19:37
  • Hi Ben, I get that this was asked 4 years ago. Wrote it in case someone stumbles upon this question looking for a solution - as I have. Feb 13, 2021 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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