如何在没有错误格式的情况下将源代码粘贴到vim? [英] How to paste source code to vim without error format?

查看:113
本文介绍了如何在没有错误格式的情况下将源代码粘贴到vim?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我复制python代码并将其粘贴到vim时.缩进都是错误的. 但我将其粘贴到emacs或gedit中,是正确的.

When I copy a python code, and paste to vim. the indents are all error. but I paste into emacs or gedit, it is right.

,让我们看一下屏幕截图. 注意:蓝线和黄线仅用于缩进指南插件".

that is difficult to describle, let's see the screenshot. Notice:the blue and yellow line is just use the "indent guides plugin".

这是源代码示例:

import threading
import time
class timer(threading.Thread): #The timer class is derived from the class threading.Thread
    def __init__(self, num, interval):
        threading.Thread.__init__(self)
        self.thread_num = num
        self.interval = interval
        self.thread_stop = False

    def run(self): #Overwrite run() method, put what you want the thread do here
        while not self.thread_stop:
            print 'Thread Object(%d), Time:%s/n' %(self.thread_num, time.ctime())
            time.sleep(self.interval)
    def stop(self):
        self.thread_stop = True


def test():
    thread1 = timer(1, 1)
    thread2 = timer(2, 2)
    thread1.start()
    thread2.start()
    time.sleep(10)
    thread1.stop()
    thread2.stop()
    return

if __name__ == '__main__':
    test()

推荐答案

自动缩进.

禁用它的最简单方法是::set paste

The easiest way to disable it is: :set paste

:help paste

'paste'                 boolean (default off)      
                        global
                        {not in Vi}
    Put Vim in Paste mode.  This is useful if you want to cut or copy
    some text from one window and paste it in Vim.  This will avoid
    unexpected effects.
    Setting this option is useful when using Vim in a terminal, where Vim
    cannot distinguish between typed text and pasted text.  In the GUI, Vim
    knows about pasting and will mostly do the right thing without 'paste'
    being set.  The same is true for a terminal where Vim handles the
    mouse clicks itself.

这篇关于如何在没有错误格式的情况下将源代码粘贴到vim?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆