在Mac OS X上删除Vim中凌乱的前导空格

Tho*_*wne 5 macos vim

我正在从网站matplotlib复制代码并粘贴到Mac OS X终端上的Vim编辑器中:

pylab_examples示例代码:ellipse_demo.py

虽然这在BBEdit中工作正常:

`from pylab import figure, show, rand
from matplotlib.patches import Ellipse

NUM = 250

ells = [Ellipse(xy=rand(2)*10, width=rand(), height=rand(), angle=rand()*360)
        for i in xrange(NUM)]

fig = figure()
ax = fig.add_subplot(111, aspect='equal')
for e in ells:
    ax.add_artist(e)
    e.set_clip_box(ax.bbox)
    e.set_alpha(rand())
    e.set_facecolor(rand(3))

ax.set_xlim(0, 10)
ax.set_ylim(0, 10)

show()
Run Code Online (Sandbox Code Playgroud)

也就是说,所有代码都已正确对齐.在Vim中它看起来像这样:

from pylab import figure, show, rand
from matplotlib.patches import Ellipse

NUM = 250

ells = [Ellipse(xy=rand(2)*10, width=rand(), height=rand(), angle=rand()*360)
        for i in xrange(NUM)]

            fig = figure()
            ax = fig.add_subplot(111, aspect='equal')
            for e in ells:
                    ax.add_artist(e)
                        e.set_clip_box(ax.bbox)
                            e.set_alpha(rand())
                                e.set_facecolor(rand(3))

                                ax.set_xlim(0, 10)
                                ax.set_ylim(0, 10)

                                show()
Run Code Online (Sandbox Code Playgroud)

如何解决这个恼人的情况?它是否与Mac上的不同回车/换行约定有关?

Gre*_*ill 17

:set paste在粘贴文本之前使用该命令.这会关闭autoindent以及其他可能干扰粘贴的事情.要恢复正常操作,请使用:set nopaste.