Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Eclipse have a way to alphabetically sort lines within a selection of text?

Similar to emacs' M-x sort-lines

like image 810
Aaron Fi Avatar asked Sep 03 '10 00:09

Aaron Fi


People also ask

How do I sort lines in eclipse?

To use after installing: select a bunch of lines → right click → Sort → Case-Sensitive A-z. Done!

How do I sort lines alphabetically?

Go to Home > Sort. Set Sort by to Paragraphs and Text. Choose Ascending (A to Z) or Descending (Z to A). Select OK.


6 Answers

Yes, it does! There is a very simple plugin called SortIt that does exactly what you want. It adds a section in the Edit menu, through which you can do the following:

  • Case Sensitive
  • Case Insensitive
  • Reverse Text
  • Numeric Sort
  • Length Sort

The plugin is source-code agnostic, and it treats whatever you sort as plain text. I find it especially useful when sorting .properties files and setters/getters. For example, using the Case Sensitive sorting I sorted the following code:

msgHeader.setTotalGrossMass(content.getTotalGrossMass());
msgHeader.setReferenceNumber(content.getReferenceNumber());
msgHeader.setTransportModeAtBorder(content.getTransportModeAtBorder());
msgHeader.setCountryOfDestinationCode(content.getCountryOfDestinationCode());
msgHeader.setCountryOfDispatchExportCode(content.getCountryOfDispatch());
msgHeader.setDateOfAmendment(content.getDeclarationDate());                     // TODO: correct?
msgHeader.setIdentityOfMeansOfTransportCrossingBorder(content.getIdentityMeansOfTransportCrossingBorder());
msgHeader.setManualEntryNumber(content.getManualEntryNumber());
msgHeader.setTotalNumberOfPackages(content.getTotalNumberOfPackages());
msgHeader.setAgreedLocationOfGoodsCode(content.getAgreedLocationCode());
msgHeader.setAgreedLocationOfGoodsLNG(content.getAgreedLoclOfGoodsLNG());
msgHeader.setManualEntryYear(content.getManualEntryYear());
msgHeader.setAgreedLocationOfGoods(content.getAgreedLocationCode());
msgHeader.setMethodOfPayment(content.getMethodOfPayment());
msgHeader.setNationalityOfMeansOfTransportCrossingBorder(content.getNationalityMeansOfTransportCrossingBorder());
msgHeader.setAmendmentPlace(content.getDeclarationPlace());                     // TODO: correct?
msgHeader.setAmendmentPlaceLNG(content.getDeclarationPlaceLNG());               // TODO: correct?
msgHeader.setTotalNumberOfItems(content.getTotalNumberOfItems());
msgHeader.setAcceptanceDate(content.getAcceptanceDate());

... to this:

msgHeader.setAcceptanceDate(content.getAcceptanceDate());
msgHeader.setAgreedLocationOfGoods(content.getAgreedLocationCode());
msgHeader.setAgreedLocationOfGoodsCode(content.getAgreedLocationCode());
msgHeader.setAgreedLocationOfGoodsLNG(content.getAgreedLoclOfGoodsLNG());
msgHeader.setAmendmentPlace(content.getDeclarationPlace());                     // TODO: correct?
msgHeader.setAmendmentPlaceLNG(content.getDeclarationPlaceLNG());               // TODO: correct?
msgHeader.setCountryOfDestinationCode(content.getCountryOfDestinationCode());
msgHeader.setCountryOfDispatchExportCode(content.getCountryOfDispatch());
msgHeader.setDateOfAmendment(content.getDeclarationDate());                     // TODO: correct?
msgHeader.setIdentityOfMeansOfTransportCrossingBorder(content.getIdentityMeansOfTransportCrossingBorder());
msgHeader.setManualEntryNumber(content.getManualEntryNumber());
msgHeader.setManualEntryYear(content.getManualEntryYear());
msgHeader.setMethodOfPayment(content.getMethodOfPayment());
msgHeader.setNationalityOfMeansOfTransportCrossingBorder(content.getNationalityMeansOfTransportCrossingBorder());
msgHeader.setReferenceNumber(content.getReferenceNumber());
msgHeader.setTotalGrossMass(content.getTotalGrossMass());
msgHeader.setTotalNumberOfItems(content.getTotalNumberOfItems());
msgHeader.setTotalNumberOfPackages(content.getTotalNumberOfPackages());
msgHeader.setTransportModeAtBorder(content.getTransportModeAtBorder());
like image 144
Markos Fragkakis Avatar answered Oct 12 '22 23:10

Markos Fragkakis


Horribly ugly website, but AnyEdit does sorting:

  • Case sensitive
  • Case insensitive
  • Numerical
  • Backward
  • Forward
like image 32
Catskul Avatar answered Oct 12 '22 23:10

Catskul


With luna you can do this by "Source" -> "Organize Imports"

This works for every type of line, not just imports.

like image 40
Rainer Hausdorf Avatar answered Oct 13 '22 01:10

Rainer Hausdorf


Try this plugin for Eclipse:

http://marketplace.eclipse.org/content/emacs

If the above one doesn't do the job, try one of these ones:

http://marketplace.eclipse.org/search/apachesolr_search/emacs

like image 22
Leniel Maccaferri Avatar answered Oct 12 '22 23:10

Leniel Maccaferri


In Eclipse Kepler SR2 I can see an option under Source > Sort Members.. It works.

I also have AnyEdit installed.

like image 39
Saikat Avatar answered Oct 13 '22 01:10

Saikat


Try CTRL+ALT+S. Works for me with Kepler.

If it doesn't work, goto Help->Key Assist... and look for "Sort Lines"

EDIT: seems to work only in the C/C++ Editor and therefore probably comes with the CDT

like image 30
clktmr Avatar answered Oct 13 '22 01:10

clktmr