Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In a terminal vim, pasting clipboard data often messes up the code indent. I just knew if I uses :set paste the indent is not broken. Though, after pasting data, should I do :set nopaste again? What if I don't, what problem comes?

share|improve this question
What about trying for yourself? Or reading the documentation? –  romainl Jun 16 '12 at 19:14
See also "Bracketed Paste Mode" in my answer to "Pasting code into terminal window into vim" stackoverflow.com/a/7053522/754997. If your terminal emulator supports it, you can arrange for it to tell Vim to switch to/from paste mode automatically whenever you paste text into the terminal. –  Chris Page Jun 25 '12 at 7:14

4 Answers 4

up vote 4 down vote accepted

As others have written, you don't want to leave 'paste' set. I just wanted to point out that with a good terminal emulator and a properly compiled and configured vim, you shouldn't need to change 'paste'. You need a good terminal emulator such as xterm or GNOME Terminal, vim with the X11 feature included, and the 'mouse' option set to 'a'. Then vim will "know" when you're pasting with the mouse and will effectively set and unset the 'paste' option for you.

One way to get a vim with the X11 feature is to run gvim with the -v option or create an alias,

alias vim='gvim -v'

Then put

set mouse=a

in your ~/.vimrc.

share|improve this answer

As romainl suggested, the documentation explains that setting the 'paste' option disables several other options, and you will certainly find that sooner rather than later it will cause problems for you. For this reason, there is the 'pastetoggle' option. See:

:help 'paste'
:help 'pastetoggle'
share|improve this answer

If something exists, it must have its meaning. You should take a good look at vim documentation which is very useful.

  :help 'paste'
  :help 'pastetoggle'

Once you read, you may want this :

" Toggle paste mode
"   (prefer this over 'pastetoggle' to echo current state)
nmap <leader>p :setlocal paste! paste?<cr>

I hope you find this post useful :)

share|improve this answer

IIRC when you paste into vim, it essentially thinks that you typed all those characters yourself. So if auto-indent is turned on, it will indent stuff for you, but the pasted text usually contains indentation already so the indent indeed gets "messed up". Switching to paste mode turns off stuff like auto-indent.

If you like auto-indent as-you-type, you should switch it back to nopaste after you're done pasting. Try it and note how you have to do all indentation manually in paste mode.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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