【问题标题】:How do I paste source code from clipboard with same formatting [duplicate]如何从剪贴板粘贴具有相同格式的源代码[重复]
【发布时间】:2014-05-21 03:29:51
【问题描述】:

我不知道为什么,但是如果我通过CTRL + V + P 快捷方式从某个外部程序复制代码,Vim 总是会弄乱我的格式。比如这个 XML 代码的 sn-p

<dependency>
    <groupId>org.jboss.test</groupId>
    <artifactId>richfaces-selenium</artifactId>
    <scope>test</scope>
</dependency>

像这样复制到 Vim 中(对不起 | 字符,即来自 indentLine 插件)

<dependency>
    │   │   │   │   │   <groupId>org.jboss.test</groupId>
    │   │   │   │   │   │   │   │   <artifactId>richfaces-selenium</artifactId>
    │   │   │   │   │   │   │   │   │   │   │   <scope>test</scope>
    │   │   │   │   │   │   │   │   │   │   │   │   │   </dependency>

那么我该如何解决这个问题呢?当我粘贴 Java 或 Python 代码时,也会发生类似的事情。

【问题讨论】:

    标签: vim formatting paste


    【解决方案1】:

    在 Vim 中使用 paste 模式,它会禁用自动缩进。这可以在插入模式下完成。 :help paste

    【讨论】:

      【解决方案2】:

      我一直有这个问题。就我个人而言,我没有尝试修复它的粘贴方式,但我在粘贴后会快速修复它。

      通过代码后,按 Esc 几次并执行此命令

      gg=G
      

      基本分类:

      gg --> Go to beginning of File
      =  --> Indent
      G  --> Go to end of File
      

      应该根据您在 .vimrc 上的缩进设置正确缩进所有内容(如果您没有缩进,那么它只会进行基本的制表符缩进)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-12-23
        • 1970-01-01
        • 1970-01-01
        • 2010-10-04
        • 1970-01-01
        • 1970-01-01
        • 2016-01-30
        • 2015-07-29
        相关资源
        最近更新 更多