3

One thing I haven't figured out is how to get vim's copy and paste to work correctly.

Can someone explain why it doesn't out of the box and how to get it to work that preserves the spacing etc?

e.g. if I copy and paste a block of code from a browser, it should paste into vim with the spacing in tact.

loyalflow
  • 12,425
  • 26
  • 90
  • 155

2 Answers2

7

Turn on paste mode with :set paste to stop vim applying any indentation to the pasted text.

desbo
  • 547
  • 4
  • 12
3

Adding to desbo's correct answer, you can quickly toggle the option with

:set paste!

Now if you have the idea "hey, a mapping is even quicker"; that won't work, as mappings are disabled in paste mode. But Vim provides a workaround through a special option:

:set pastetoggle=<F11>

Lastly, if you use the GUI-version gvim, you don't need to care about all of this, as it is able to differentiate typing from pasting by itself.

Ingo Karkat
  • 154,018
  • 15
  • 205
  • 275