Pasting into Vim Messing Up Indentation

Published: April 15, 2020


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 also dabbles in Ruby and Go. Technical topics that interest me are monitoring, security and performance.

During the day I solve challenging technical problems at Something Digital where I mainly work with the Magento platform. I also blog about tech, work on open source and hunt for bugs.

If you'd like to get in touch with me the best way is on Twitter.