Kai
Kai

Reputation: 983

New lines being inserted at the start of the lines when pasted in vim (tmux)

I use Tmux to open my terminals . When I copy and paste in Tmux, new lines are being attached at the start of the lines. For example if I copy :

Line1 to be copied.
Line2 to be copied.
Line3 to be copied. 

And if I paste the above text. It would become

Line1 to be copied.
    Line2 to be copied.
         Line3 to be copied.

I use it from mac. I select the text to be copied while pressing "alt" key and then paste it. Any suggestions on how to avoid the spaces at the start?

Note: A few more details about the environment. I have a custom tmux.conf file. Following are a few setting I use in my tmux conf.

# more settings to make copy-mode more vim-like
unbind [
bind Escape copy-mode
unbind p
bind p paste-buffer
bind -t vi-copy 'v' begin-selection
bind -t vi-copy 'y' copy-selection
bind -t vi-copy 'z' copy-pipe "reattach-to-user-namespace pbcopy"
# Buffers to/from Mac clipboard, yay tmux book from pragprog
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
bind C-v run "tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste-buffer")

Upvotes: 1

Views: 1130

Answers (2)

zkanda
zkanda

Reputation: 724

To make this automatic, you can use vim-bracketed-paste

Upvotes: 2

Clayton Perroni
Clayton Perroni

Reputation: 130

Question looks like it has been already asked.

Turning off auto indent when pasting text into vim

Sum up: Try typing:

    :set paste

before pasting your clipboard and then return it to

    :set nopaste

after, in order to resume normal formatting when entering newlines.

Upvotes: 5

Related Questions