Ubuntu: 18.04 bionic
tmux: version 2.6
VIM: Vi IMproved 8.0 (2016 Sep 12, compiled Jun 06 2019 )
Included patches: 1-1453
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
Huge version with GTK3 GUI.
My .tmux.conf file was initially empty, but then I edited by basically copying the Linux part of this answer from UnixSE. The problem below occurred both before and after I edited that conf file.

There is a website I always use (I can give out the name of the website if others believe it's relevant), and copy text from. When I'm using Vim in bash without tmux, I can paste the text to Vim without problems and it looks like this:

 Defensa de la persona humana

 Artículo  1.- La defensa de la persona humana y el respeto de su dignidad son el fin supremo de la sociedad y del Estado.


 Derechos fundamentales de la persona

However, when I'm inside tmux, the indentation 'breaks' and I get something like this:

 Defensa de la persona humana

    Artículo  1.- La defensa de la persona humana y el respeto de su dignidad son el fin supremo de la sociedad y del Estado.


          Derechos fundamentales de la persona

That has never happened when I paste the text on Vim inside bash (without tmux). And, in case it matters, the way I usually copy and paste is by selecting the text on my web browser, then pressing Ctrl+C , then going to Vim, enter Insert Mode, and finally press Ctrl+Shift+V .

Edit: This problem happens only with that specific website. However, it's not fully a problem from the website because, as explained above, the pasting works totally fine outside tmux.

How can I make Vim inside tmux paste my text the way it is in the block in the top?
What do I need to fix?

  • 1
    try using :set paste before insertion maybe ; I use tmux but I never had a similar case. – francois P Mar 5 '20 at 19:34
  • @francoisP , that command fixed the problem, thank you! I also found some other observations which I'll explain in my next edit. Please consider writing an answer to this post; I'll most probably accept it after 24 hours of waiting. – evaristegd Mar 5 '20 at 19:54
  • @francoisP , by the way, do you think I can see your .tmux.conf file? If not, what would you recommend? – evaristegd Mar 5 '20 at 19:56
  • 1
    @francoisP , your answer says 'past' instead of 'paste'. – evaristegd Mar 5 '20 at 20:32

So using :set paste first can resolv the issue.

as you asked here is my tmuxrc but it is very short :

:~$ cat ~/.tmuxrc
set -g status-utf8 on

So I don't think it is special

  • 3
    Reminder that one should unset it afterwards – D. Ben Knoble Mar 6 '20 at 13:54

Manually toggling :set paste/:set nopaste as suggested by francois P is cumbersome, and resetting the TERM variable as evaristegd suggests is a very bad idea as explained in the comments (which hint at the better solution below). The best solutions that I could find are explained here, and I'll briefly repeat them below.


The central concept for this problem is "bracketed paste mode", which lets a program distinguish between pasted and typed input. The problem is that vim 8 only enables bracketed paste mode when started with certain values for the TERM-variable (e.g. TERM=xterm-256color). Within tmux however, vim should get either TERM=screen (default) or TERM=tmux, and in neither case does vim enable bracketed paste mode (I have no idea why not, please edit if you do).


Add the following to your ~/.vimrc, as explained in the vim help: :h xterm-bracketed-paste.

if &term =~ "screen"                                                   
    let &t_BE = "\e[?2004h"                                              
    let &t_BD = "\e[?2004l"                                              
    exec "set t_PS=\e[200~"                                              
    exec "set t_PE=\e[201~"                                              

Edit: As pointed out by others, the original answer is wrong, and I plan to delete it later, if the admins don't oppose to it. For a good answer, please check DiningPhilosopher's one.
If you want to see the original answer, you can check the edit history.

  • 2
    For anyone reading this answer, setting 'default-terminal' to anything other than "screen", "tmux" or a derivative is wrong; it will lead to other issues. Before setting any option, read the only source of reliable information about tmux, which is not this site, not stackoverflow, nor some blog post, but the man page. – user938271 Mar 6 '20 at 7:06
  • @user938271 , thank you for bringing this to my attention. I will review your sources. – evaristegd Mar 6 '20 at 14:48
  • 1
    1. The main difference is that it assigns a correct value; i.e. screen-256color is ok, xterm or xterm-256color is not. 2. By writing xterm or xterm-256color, you're making Tmux initialize $TERM with a value which tells all the applications (not just Vim) that they're talking to the xterm terminal, which is a lie; they are not talking to xterm directly (in fact the outer terminal may not even be xterm); they are talking to the Tmux terminal. They will now query a wrong entry in the terminfo database when they'll need to use a terminal capability. – user938271 May 23 '20 at 8:52
  • 1
    3. Your issue is probably due to Vim which doesn't enable the bracketed paste mode. If that's the case, then the best solution is not to meddle with Tmux but with Vim, and to configure terminal options as explained at :h xterm-bracketed-paste. 4. The reason why your line "fixes" the issue is probably because when Vim thinks it's talking to xterm, it automatically configures the terminal options for you. But a good fix should not introduce regressions, which set -g default-terminal "xterm" does. – user938271 May 23 '20 at 8:52

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.