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?
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
# DEFINITION
def zzz
...
end
# END DEF
then 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
:'<,'>!sort
then split on the inserted pattern...
Still less than ideal, but it can be done...
See this answer too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With