When pasting text through a terminal emulator, the auto-indent feature may destroy the indentation of the pasted text.
For example:
function () {
echo 'foo'
echo 'bar'
echo 'baz'
}
will be pasted as:
function () {
echo 'foo'
echo 'bar'
echo 'baz'
}
In these cases, use the paste/nopaste option to disable / enable the auto-indent feature:
:set paste
:set nopaste
Adding to this, there is a simpler approach to the problem: Add the following line in your .vimrc:
set pastetoggle=<F3>
And if you want to paste as is from the clipboard. Just press F3 in insert mode, and paste. Press F3 again to exit from the paste mode.