Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
How can I keep the code formated as original source when I paste them to vim?

This is a portion of my .vimrc file.

" when opening a Python file, use spaces instead of tabs (et, expandtabs),
" use 4 spaces as tabulation (ts=4, tabstop), use 4 spaces when adding
" a tabulation automatically (sw=4, shiftwidth) and thread 4 spaces as
" a tabulation when deleting (softtabstop=4)
au FileType python set et ts=4 sw=4 softtabstop=4

autocmd BufRead *.py set makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
autocmd BufRead *.py set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
autocmd BufRead *.py nmap <F5> :!python %<CR>

It works very well for editing python. However, when I need to paste pre-indented python code into a python file from my clipboard buffer I end up with something that looks like this:

class GlobalOptions:
        def __init__(self):
                                self.DebugLevel = 0

def __repr__(self):
                    return "<GO>"

This occurs even if I use ':set noautoindent' .

Is there a simple way to toggle between intelligent autoindenting of python files and a raw entry mode that can be used for pasting code?

I'd be happy to experiment with someone elses .vimrc file if it avoids this problem.

I have encountered this problem on vim 6.3, 7.0, 7.1 running on Debian, RedHat and Ubuntu respectively.

share|improve this question

marked as duplicate by Ignacio Vazquez-Abrams, Heptite, slhck, Daniel Andersson, Breakthrough Jul 17 '12 at 19:10

This question was marked as an exact duplicate of an existing question.

up vote 0 down vote accepted

You need to :set paste! before and after pasting things from your system clipboard into vim.

share|improve this answer

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