开发者

Vim: sort classes in a python source file

开发者 https://www.devze.com 2022-12-22 15:28 出处:网络
I have a .py file with lots of classes: class First(Second): #code class Third(Fourth): #code Is it possible to sort the definitions by class name i开发者_StackOverflow中文版n vim?Suggestion for m

I have a .py file with lots of classes:

class First(Second):
    #code

class Third(Fourth):
    #code

Is it possible to sort the definitions by class name i开发者_StackOverflow中文版n vim?


Suggestion for manual sorting.

With a reasonable amount of classes, manual sorting is not so tedious. I also propose it since I think it makes much more sense to group superclasses together and make sure superclasses are defined before subclasses -- otherwise your module won't even be importable.

Enable folding in Vim:

set foldmethod=indent

you can open a fold with zo, close with zc. Close all in the document with zM, open all in the document with zR.

Close all folds in the document. Now each class spans only two lines, and it's easy to delete and reinsert in its proper place.

0

精彩评论

暂无评论...
验证码 换一张
取 消