Pro tip: after you paste code, it might not be indented correctly in the new context. You can select just pasted lines and autoindent them with V`]=. This should fix the indentation in most cases.
A better alternative: issue the ":set paste" command just before pasting text. That way you keep the original indentation.
A better alternative: issue the ":set paste" command just before pasting text. That way you keep the original indentation.