2012-03-22 12 views
19

Cuando copio un código python, y pego a vim. las sangrías son todo error. pero pego en emacs o gedit, es correcto.¿Cómo pegar el código fuente a vim sin formato de error?

que es difícil de describir, veamos la captura de pantalla. Aviso: la línea azul y amarilla es solo usar el "complemento de guías de sangrado". the screenshot

Este es el ejemplo de código fuente:.

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() 

Respuesta

32

sangrado automático patada en

La forma más fácil de desactivarlo es: :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. 
+0

Muchas gracias. Si abro el modo Pegar, ¿hay alguna influencia en las otras cosas, por ejemplo, como editar el código, etc.? –

+0

simplemente deshabilita todas las configuraciones relacionadas con el formato del texto de entrada. ver ': ayudar a pegar' –

9

Karoly de la respuesta es correcta con respecto a la opción paste.

A continuación, puede agregar una asignación en su .vimrc para permitir de forma rápida/desactivar la opción de 'pegar':

Por ejemplo, utilizo set pastetoggle=<F10>

Cuestiones relacionadas