Vim indents every line of code when copying

When I copy and past a block of code in Vim, every line gets indented by one. For example, I have this source:

    print "Hello"
    print "World"
    print "I'm copying"
    print "and pasting"

Which gets jumbled when pasting into Vim:

print "Hello"
        print "World"
            print "I'm copying"
                print "and pasting"

For copying long lines of code, it's very frustrating because everything gets out of alignment (not good for python).

Here is my vimrc. It currently auto-indents on newlines, and replaces tabs with the standard 4 spaces.

filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab

While this config works, something is causing the copy-paste problem. How can this be fixed, but still retain the behaviors that I've defined?


Use :set paste to switch to paste mode.

This article explains paste mode

It was made specifically for pasting text into vim so it doesn't trigger any input mappings. Remember to :set nopaste when you are done to get your mappings back.

链接地址: http://www.djcxy.com/p/8730.html

上一篇: 什么是vim录制以及如何禁用它?

下一篇: Vim在复制时缩进每行代码