Tag Archives: vim turn off auto indent when pasting

How to turn off auto indent when pasting stuff into vim on the terminal

You can turn on automatic indenting in vim by setting the indentexpr option. You can turn it on by adding the below line to your ~/.vimrc.

While automatic indentation is almost the next best thing to baked bread, especially when you code on a remote server, it’s also painful when you want to paste something from your local machine’s clipboard, vim goes overboard and indents code like this:

Vim auto indenting

Vim auto indenting

In order to be able to paste stuff from clipboard into a file open in vim via a terminal without vim auto indenting it badly, you need to enable the paste mode.

By typing

you can enable the paste mode, which will let you paste stuff without vim indenting it multiple times

By typing

you can go back to the auto-indent mode.

This can also be toggled easily by using the following command:

Now, it can be a little bit of a pain to remember to toggle between the paste mode on and off. A good samaritan has written a vim pathogen bundle that makes this automatic.

Vim Bracketed Paste plugin lets you easily paste stuff without having to toggle paste modes.

Installing vim bracketed paste plugin is easy:

  1. Install pathogen first.

  2. Install vim bracketed paste


Hope this helps!