Text copied from vim inside a tmux session is padded with spaces to the right

copy-paste, tmux, vim

Solution

After more investigation I found the root of the problem. It's because tmux does not support the `bce` feature. From the xterm FAQ:

The term "bce" stands for "back color erase". Terminals such as modern xterm and rxvt implement back color erase, others such as dtterm do not. (Roughly half of the emulators that I know about implement bce). When an application clears the screen, a terminal that implements back color erase will retain the last-set background color. A terminal that does not implement back color erase will reset the background color to the default or initial colors. Applications that paint most of the screen in a single color are more efficient on terminals that support back color erase. Inevitably, there are tradeoffs and issues with standardization of the feature as noted in the ncurses FAQ. Unsurprisingly, ncurses supports xterm's behavior.

The original `screen` multiplexer had this feature. I've opened a feature request issue, but unfortunately they refused to implement it. So the hard truth is: There's no solution with tmux.

UPDATE: For those checking the feature request - Good luck! The author is very opinionated and reacts quite thin-skinned. He completely banned me from the repository, because I dared to counter one of his snotty comments. Take care.

Problem

When I run Vim from inside a tmux session and copy some text to the clipboard, each line gets padded with spaces to the right. For example, say I have a text file like this: ``` ^some$ ^text$ ``` Note: I've used `^` and `$` to mark the beginning and end of a line respectively. They are not part of the file content. I start tmux and open this file in Vim. I press Shift (to prevent Vim from processing the mouse click) and mark the complete text by holding the left mouse button clicked. Then I copy it to the clipboard with Shift+Ctrl+c. The result in the clipboard is something like: ``` ^some $ ^text $ ``` Note the extra spaces. The number of spaces depends on the terminal width. If I start Vim without tmux or if I just `cat` the file content and then copy it, there are no extra spaces. So it must have to do with the combination of Vim + tmux. I've seen this on different Linux flavours, i.e. on Ubuntu and Mint. I use the default terminal (Gnome Terminal 3.6.2) there. So how can I prevent this? EDIT: My `tmux.conf` ``` set-option -g prefix C-a set-option -g mouse-utf8 off set-option -g status-keys vi set-window-option -g mode-keys vi set-window-option -g mode-mouse on set-option -g terminal-overrides 'xterm*:smcup@:rmcup@' bind-key C-a last-window bind-key C-h select-pane -L bind-key C-l select-pane -R # colors: set-option -g status-bg black set-option -g status-fg white set-option -g status-left '#[fg=green]#H' set-window-option -g window-status-current-bg red ``` EDIT 2: I've also tried without the above `.tmux.conf`, using tmux' default settings - no difference.

Original source