当我将文本从浏览器复制并粘贴到文件时,为什么Vim再次缩进每一行?

时间:2019-06-22 02:53:45

标签: vim

当我将一些文本从浏览器窗口复制到我正在用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

1 个答案:

答案 0 :(得分:3)

您可能启用了autoindentcindent。当您选择其中一个选项时,Vim不会知道粘贴到终端中的换行符与您自己输入的换行符之间的区别。因此,当您粘贴换行符时,Vim会对行进行缩进,然后还粘贴空格以提供额外的缩进,以此类推,直到下一行,直到您在屏幕上超出所需的距离为止。

解决方案是使用:set paste设置粘贴模式,然后粘贴,然后使用:set nopaste关闭粘贴模式。在粘贴模式下,Vim不会自动缩进行,因此将大量行粘贴到终端中不会导致缩进。

如果您的特定平台上有支持剪贴板的Vim,则也可以使用"*"+寄存器(例如,使用"*p进行粘贴)粘贴,不会也有问题。