Disculpe la pregunta de novato, pero he leído el manual, esta pregunta, y lo intenté varias veces sin los resultados que esperaba.
Así que estaba usando vim para editar un archivo (adjunto). Pero al ejecutar, obtuve TabError: uso inconsistente de tabulaciones y espacios en error de sangría.
Esto es lo que he probado:
:retab y :x . Vuelva a ejecutar el archivo. Todavía recibí el mensaje TabError.:retab! y :x . Vuelva a ejecutar el archivo. Todavía recibí el mensaje TabError.:retab! 4 y :x . Vuelva a ejecutar el archivo. Esta vez funciona, pero no tengo idea de por qué. Además, en los archivos la sangría parece excesivamente larga. (Leí aquí que el editor podría mostrar 8 espacios para una pestaña)Mis preguntas son:
¿Qué significa :retab , :retab! , y :retab! 4 significa?
¿Por qué :retab no funciona en mi archivo?
#!/usr/bin/env python #Reduce function for computing matrix multiply A*B #Input arguments: #variable n should be set to the inner dimension of the matrix product (ie, the number of columns of A/rows of B) import sys import string import numpy #number of columns of A/rows of B n = int(sys.argv[1]) #Create data structures to hold the current row/column values (if needed; your code goes here) currentkey = None alist = [] # list for elelents in A blist = [] # list for elements in B # input comes from STDIN (stream data that goes to the program) for line in sys.stdin: #Remove leading and trailing whitespace line = line.strip() #Get key/value key, value = line.split('\t',1) print(key, value) #Parse key/value input (your code goes here) key = (key.split(',', 1)[0], key.split(',',1)[1]) value = (value.split(',', 1)[0], value.split(',',1)[1], value.split(',',1)[2]) #If we are still on the same key... if key==currentkey: #Process key/value pair (your code goes here) # store all values in a lisl if value[0]=='A': alist.append([value[1], value[2]]) else: blist.append([value[1], value[2]]) #Otherwise, if this is a new key... else: #If this is a new key and not the first key we've seen, ie currentkey!=None if currentkey: #compute/output result to STDOUT (your code goes here) alist = sorted(alist) blist = sorted(blist) newlist = [a[1]*b[1] for a,b in zip(alist, blist)] res = newlist.sum() print(currentkey, res) currentkey = key #Process input for new key (your code goes here)Simplemente escriba :help retab en Vim y lea. Creo que no puedo explicarlo mejor que la ayuda. Tal vez te falte la parte del rango opcional; use el prefijo % para aplicar a todo el archivo. También es útil :set list para mostrarte todos los caracteres; esto le mostrará las pestañas y los extremos de línea (deshabilitar con :set nolist ) y :set <name> sin valor para ver el valor actual, por ejemplo : set tabstop o seguido de algún valor para establecer.
Al mostrar todos los caracteres, habilitar y deshabilitar la expansión de pestañas en espacios con :set expandtab y :set noexpandtab , configurando tabstop y usando, por ejemplo. :retab! 4 puede jugar a su manera y cambiar entre solo pestañas y solo espacios, y cambiar el ancho de la columna de la pestaña.
Este enlace, la configuración de vim para python también podría ser útil
Esc
:%s/\t/ /gSignifica reemplazar la pestaña con 4 espacios. Presiona Enter Esc
:wqMientras intenta ejecutar :retab podría no funcionar si ha copiado el código pegado y comenzó a editarlo.
Puede intentar establecer la configuración de vim/vi primero:
sudo mkdir ~/.vim && sudo touch ~/.vim/vimrc para crear un archivo de configuraciónvimrc para agregar el siguiente fragmento set softtabstop=4 set tabstop=4 set shiftwidth=4 set expandtab:retab