问题
class MyClass
def zzz
# method body
end
def aaa
# method body
end
end
How would I get VIM to organise these into alphabetical order such that the definition of aaa precedes the definition of zzz?
回答1:
Well you can set up code folding e.g. by indentation, and close those functions/fold, then do it manuall with dd then p but that is not an ideal solution with a large file.
It's not an easy task. You can set up some line-joining, e.g.:
put some specific comment/identifier before every first level
def, like# DEFINITIONdef zzz...end# END DEFthen join those lines into one with some multiline regex magic (and/or column editing), using some placeholder which generally does not occur in your code.
then sort it via standard unix sort (e.g. visually select your joined lines, then
:'<,'>!sortthen split on the inserted pattern...
Still less than ideal, but it can be done...
See this answer too.
来源:https://stackoverflow.com/questions/9064425/how-to-sort-methods-into-alphabetical-order-in-vim