Vim copy paste adding newlines

Vim is adding lots of spaces and newlines when copy / pasting. This is what it looks like:

How do I fix this?

2

3 Answers

Gedit is using 4 spaces per indent, your VIM looks like it's using 8 spaces per indent.

There's nothing wrong, just a simple setting difference.

Look up the options:

  • shiftwidth
  • softtabstop
  • tabstop
  • expandtab

:set sw=4 sts=4 ts=8 et

will make your VIM look like your Gedit.

5

I assume you're pasting from the clipboard or something? Try :set paste before pasting.

The first thing I do on any new machine is put set paste in my vimrc. I prefer paste mode as the default behaviour.

Edit: And you can use :set nopaste to turn paste mode off and the auto-format back on.

2

you probably have vim's autoindent mode on. try turning it off with :set noautoindent

also, as mentioned by CR above, :set paste greatly improves vim's behaviour while pasting text into it...with paste mode set you don't need to mess around manually setting text-width, wrap-margin or anything else likely to mess up long lines or text spacing. remember to use :set nopaste when you've finished pasting.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like