当我从浏览器窗口复制一些文本到我用 Vim 编辑的文件时,为什么会出现这个?如何让线条正确排列?
from django.db import models
from django.contrib.gis.db import models
# Create your models here.
class WorldBorder(models.Model):
# Regular Django fields corresponding to the attributes in the
# world borders shapefile.
name = models.CharField(max_length=50)
area = models.IntegerField()
pop2005 = models.IntegerField('Population 2005')
fips = models.CharField('FIPS Code', max_length=2)
iso2 = models.CharField('2 Digit ISO', max_length=2)
iso3 = models.CharField('3 Digit ISO', max_length=3)
un = models.IntegerField('United Nations Code')
region = models.IntegerField('Region Code')
subregion = models.IntegerField('Sub-Region Code')
lon = models.FloatField()
lat = models.FloatField()
# GeoDjango-specific: a geometry field (MultiPolygonField)
mpoly = models.MultiPolygonField()
# Returns the string representation of the model.
def __str__(self): # __unicode__ on Python 2
return self.name
最佳答案
您可能打开了 autoindent
或 cindent
。当你打开这些选项之一时,Vim 不知道粘贴到终端的换行符和你自己输入的换行符之间的区别。因此,当您粘贴一个换行符时,Vim 会缩进该行,然后您还可以粘贴空格以提供额外的缩进,在下一行依此类推,直到您在屏幕上的位置比您想要的要远得多。
解决办法是用:set paste
设置粘贴模式然后粘贴,再用:set nopaste
关闭粘贴模式。在粘贴模式下,Vim 不会自动缩进行,因此将大量行粘贴到终端中不会导致缩进不断增加。
如果你的 Vim 在你的特定平台上支持剪贴板,你也可以使用 "*
和 "+
寄存器进行粘贴(例如使用 "* p
粘贴),也不会有这个问题。
关于vim - 当我将文本从浏览器复制并粘贴到文件时,为什么 Vim 会再次缩进每一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56712235/