Web Dev Blog

Looking for help with WordPress, Apache, Vim, Web Security and more. Here are a few tips.

Automatically Change Indent When Pasting in Vim

For years I’ve been trying to figure out how to keep Vim from automatically indenting when I copy from one file to another.

Stackoverflow mentioned this page buy a developer named Marcin Kulik

Automatically set paste mode in Vim when pasting in insert mode

let &t_SI .= "\[?2004h"
let &t_EI .= "\[?2004l"

inoremap [200~ XTermPasteBegin()

function! XTermPasteBegin()
set pastetoggle=[201~
set paste
return ""

This code automatically turns off the Vim indent functionality when new text is pasted into a file. Just add it to your .vimrc file.

It’s the same as a set paste and set nopaste before and after pasting new text, but it happens automatically. I’ve tested it and it seems to be working PERFECT. I love it!

Leave a Reply