Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been trying to paste text from one file to another in bash. I'm working in Putty.

To be more clear, I have a file hotel.txt with some lines of text that are indented, thus have tabs and spaces. When I paste a few of those indented lines into another file created using vi, they are pasted with a tab extra each.

All my text is automatically indented with each line having an extra tab as soon as I paste using the right click mouse button.

Does anyone have any solution?

I've tried :set paste, but doesn't work with me apparently.

share|improve this question

migrated from Aug 21 '13 at 23:55

This question came from our site for professional and enthusiast programmers.

general coding advice: It is good practice to replace tabs by spaces. Most editors have such configuration option – hek2mgl Aug 21 '13 at 11:55
Do you mean while indenting my script, I must use spaces? Thanks alot! – st1046 Aug 21 '13 at 11:59
@hek2mgl I've heard the other way around. So do most of the people here – Antarus Aug 21 '13 at 11:59
Yes, in the moment you are coding. My editor for example (vim) inserts 4 spaces when I press tab. I have set expandtab and set ts=4 in my vimrc. This makes things easier, believe me.. :) – hek2mgl Aug 21 '13 at 12:00
It's odd that :se paste doesn't work. – devnull Aug 21 '13 at 12:00
up vote 0 down vote accepted

While in vi, enter the escape mode using Esc. Then say :set paste.

Now you should be able to paste text unmodified.

You can turn 'paste' off by saying :set nopaste.

In order to make the change permanent, you can add :set paste to your ${HOME}/.vimrc.

share|improve this answer
Just tried it exactly this way. Not working. The text is still indented unncessarily. – st1046 Aug 21 '13 at 13:25
What about :set noautoindent? Does that work? – devnull Aug 21 '13 at 13:27
Yes that works perfectly fine. Thank you so very much!Thats a big relief. – st1046 Aug 21 '13 at 13:44

This happens because you're either not copying the indentation of the first line or because you're pasting on an already indented position.

share|improve this answer
I didn't quite understand you. I create a new file, lets say by vi example and paste my copied and indented code immediately after pressing 'I'. It still creates all the unnecessary indentation. – st1046 Aug 21 '13 at 11:59

Its not exactly an answer but you can remove the extra tab in the beginning this way


where ^I is the tab character and you can type it by pressing C-v and then tab.

(or type the following sequence

gg    "goto top
c-v   "visual selection
S-G   "goto end of file
<<    " indent visual selection one to the left.


share|improve this answer

You must log in to answer this question.