Pasting into Vim Messing Up Indentation

Published: April 15, 2020

Tags:

This morning I was trying to paste so XML from a local file into a remote file using Vim. However when I did it, it was messing up the indentation really badly, essentially indenting each new line an additional level.

Screenshot of messed up indentation in Vim

Some Googling brought me the article “How to stop auto indenting” on the Vim Tips Wiki. The article is thoroughly details the many different options to control Vim’s auto-indentation.

For me, the best option was “Disabling auto indent temporarily to paste” as I was in the middle of production maintenance and didn’t want to think about the best long term configuration.

With the file open while in normal mode enter the following command:

:set paste

Now you can paste text without having the indentation method messed up:

Screenshot show Vim paste command

Max Chadwick Hi, I'm Max!

I'm a software developer who mainly works in PHP, but loves dabbling in other languages like Go and Ruby. Technical topics that interest me are monitoring, security and performance. I'm also a stickler for good documentation and clear technical writing.

During the day I lead a team of developers and solve challenging technical problems at Rightpoint where I mainly work with the Magento platform. I've also spoken at a number of events.

In my spare time I blog about tech, work on open source and participate in bug bounty programs.

If you'd like to get in contact, you can find me on Twitter and LinkedIn.