Thursday, June 27, 2013

Using Vim to break long Python import statements

You can use ...

    :%s/^\(from.*\)\(import.*[a-z]\)\%>79v/\1\\\r\t\2/g

... to change long lines like ...

from experimental.tools.musicexpressiontools.RhythmRegionExpression import RhythmRegionExpression

... to two shorter lines like this ...

from experimental.tools.musicexpressiontools.RhythmRegionExpression \
    import RhythmRegionExpression

... in a single command.

No comments: