Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove messy leading whitespace in Vim on Mac OS X

Tags:

vim

macos

I am copying code from website matplotlib and pasting into the Vim editor in a terminal on Mac OS X:

pylab_examples example code: ellipse_demo.py

While this works fine in 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()

That is, all the code is properly aligned. In Vim it looks like this:

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()

How to fix this annoying situation? Does it have something to do with the different carriage return / line feed conventions on the Mac?

like image 240
Thomas Browne Avatar asked Jul 11 '09 23:07

Thomas Browne


1 Answers

Use the :set paste command before pasting the text. This turns off autoindent plus various other things that can interfere with pasting. To restore normal operation, use :set nopaste.

like image 51
Greg Hewgill Avatar answered Nov 15 '22 06:11

Greg Hewgill