When i'm in Insert mode at vim, and press Shift+Insert to paste my code to my file, vim disassembles my indentation , Such as:

my indentation has been disassembled by vim

Question: How can i solve this problem?

  • Use "+p to paste!
    – Ry-
    Dec 2 '14 at 2:56

Vim is acting as if you had typed all of your pasted code by hand, so Vim will add additional indentation and otherwise change whitespace as it normally would, such as with your autoindent setting. To paste code in Vim:

  1. :set paste to enable paste mode.
  2. Paste your code.
  3. :set nopaste to disable paste mode so your normal typing will work as expected again.

And see :help paste for more information, including which options are disabled/altered when paste mode is on.

It's possible to set up mappings for this sort of thing if you do it a lot. See :help imap for more information on that.



:set paste

Above code solves your problem.

Not the answer you're looking for? Browse other questions tagged or ask your own question.