当我将一些文本从浏览器窗口复制到我正在使用 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来粘贴),这也不会有这个问题。