By default VI editor is in normal mode. So we have to enable the paste mode and to activate this before copying the code type below:
Now go to insert mode by pressing i and paste your code.
After pasting the codes in VI editor, get out of the paste mode hit ESC and type:
which will take you back to the normal mode.