I have a strange problem when copying/pasting a group of lines within vi. For example, let us say we have a group of lines as follows:
AAAAAAAA AAAAAAAAAAAAAA
BBBBBB BBBBB BBBBBBBBBB
CCCCC CCC CCCCCCCC CCCCIf I copy these lines and paste it, the lines are pasted like this
AAAAA AAAAAAAAAA BBBBBBBB BBBBBB BBBBBBBBBBB CCCCC CCC CCCCCCCC CCCCThe value of TERM environment variable is vt320. I don't know if this has an effect. But it worked before. I open a session using putty. Any clues?
1 Answer
This is presumably because of the paste option. From :h paste:
*'paste'* *'nopaste'*
'paste' boolean (default off) global {not in Vi} Put Vim in Paste mode. This is useful if you want to cut or copy some text from one window and paste it in Vim. This will avoid unexpected effects. Setting this option is useful when using Vim in a terminal, where Vim cannot distinguish between typed text and pasted text. In the GUI, Vim knows about pasting and will mostly do the right thing without 'paste' being set. The same is true for a terminal where Vim handles the mouse clicks itself.I'd assume this is happening because you have some indent settings, so as you paste, vim assumes you're typing instead of pasting, and adds the necessary indents automatically. If you :set paste, it will stop doing this.
Of course, one other solution is to use gvim instead of a terminal. It's up to you whether this option worth it to you.