Eclipse 是否可以按字母顺序对所选文本中的行进行排序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3632206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does Eclipse have a way to alphabetically sort lines within a selection of text?
提问by Aaron Fi
Similar to emacs' M-x sort-lines
类似于 emacs 的 Mx 排序行
采纳答案by Leniel Maccaferri
Try this plugin for Eclipse:
试试这个 Eclipse 插件:
http://marketplace.eclipse.org/content/emacs
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
http://marketplace.eclipse.org/search/apachesolr_search/emacs
回答by Markos Fragkakis
Yes, it does! There is a very simple plugin called SortItthat does exactly what you want. It adds a section in the Edit menu, through which you can do the following:
是的,它确实!有一个非常简单的插件叫做SortIt,它完全符合你的要求。它在“编辑”菜单中添加了一个部分,您可以通过该部分执行以下操作:
- 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:
该插件与源代码无关,它将您排序的任何内容视为纯文本。我发现它在对.properties
文件和 setter/getter 进行排序时特别有用。例如,使用区分大小写排序,我对以下代码进行排序:
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());
回答by Catskul
回答by Rainer Hausdorf
With luna you can do this by "Source" -> "Organize Imports"
使用 luna,您可以通过“来源”->“组织导入”来执行此操作
This works for every type of line, not just imports.
这适用于每种类型的行,而不仅仅是导入。
回答by Saikat
回答by clktmr
Try CTRL+ALT+S. Works for me with Kepler.
试试CTRL+ ALT+ S。与开普勒一起对我来说有效。
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
编辑:似乎只能在 C/C++ 编辑器中工作,因此可能随 CDT 一起提供
回答by user1050755
If you are under Linux, simply use "cat file | sort". Under Windows, as a programmer, you should probably have cygwin installed anyways.
如果您在 Linux 下,只需使用“cat file | sort”。在 Windows 下,作为程序员,无论如何你应该安装 cygwin。