【问题标题】:Vim indents every line of code when copying-pastingVim 在复制粘贴时缩进每一行代码
【发布时间】:2017-04-27 13:45:09
【问题描述】:

当我在 Vim 中复制并粘贴一段代码时,每一行都会缩进一个。例如,我有这个来源:

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

粘贴到 Vim 时会变得混乱:

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

对于复制长行代码,这是非常令人沮丧的,因为一切都失去了对齐(对 python 不利)。

这是我的 vimrc。它目前自动缩进换行符,并用标准的 4 个空格替换制表符。

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

虽然此配置有效,但某些原因导致了复制粘贴问题。如何解决此问题,但仍保留我定义的行为?

【问题讨论】:

标签: vim indentation


【解决方案1】:

使用:set paste 切换到粘贴模式。

This article explains paste mode

它专门用于将文本粘贴到 vim 中,因此不会触发任何输入映射。完成后请记住:set nopaste 以取回映射。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    相关资源
    最近更新 更多