In the Eclipse text editor, how can I reformat / fill / justify a paragraph to 80 characters wide?

北慕城南 提交于 2019-12-08 18:07:53

问题


When editing text files in Eclipse, for instance, a README file, I have not yet found a way to get the editor to reformat paragraphs of text so that they fit in a reasonable width (typically 80 characters). This seems like it should be a very common thing to want to do, but I haven't found it. Can anyone help?

Note that I'm not talking about soft text wrapping here - I want to hit some key combination and have Eclipse insert and remove actual newline characters so that the file looks OK when viewed in a basic text editor. Essentially, the same thing that the 'fill-paragraph' function on Emacs does. I'm aware that certain specific source code editors have intelligent reformatters that work with comments, but the basic text editor doesn't seem to have anything.

If this doesn't exist I may have to go and write something myself...


回答1:


No, Eclipse is not able to format plain text files.

But, there is a workaround: create a new empty Java class, place your text inside comments (/* ... */), and click Source -> Format (Ctrl+Shift+F).




回答2:


You could try some Monkey script for wrapping selected text (but that was for Eclipse 3.2 or 3.3 with Eclipse Monkey, not sure about a current Helios Eclipse).

You can check if this TeXlipse plugin would still be compatible with an Eclipse 3.5 or 3.6, but it is a Latex Mode Editor plugin only...

But other than those attempts to bring wrapping to the Eclipse Editor world, no, so far no luck.
The famous bug 35779 presents all the gory details of the wrapping affair and Eclipse.
There was a project back in 2006 to introduce true wrapping.
But its only conclusion was... that is wasn't so easy: see his comment#75.


senarvi comments below:

TeXlipse seems to be relatively well maintained and available for the newest Eclipse (4.2).
It allows reformatting a paragraph by pressing Esc+Q or selecting Latex > Correct Line Wrap.
Bug 35779 is about the kind of word wrap mode that splits long lines in the editor window but leaves the physical lines intact, which is a different thing.




回答3:


You can use Eclipse to reformat your text:

Turn on regular expressions in the Find/Replace Dialog.

Do a find/replace of "(.{70,79}?) " with "\1\n" on the entire text, that should do the job.




回答4:


I have not found a way to do it inside Eclipse (Ctrl-Alt-F would be really nice).

A simple way is to open the underlying file in an external editor, do what you need and then save the result. If properly set up in your operating system, you can simply right-click the file in the Project Explorer or Navigator and choose "Open With -> System Editor".

Otherwise you can get the full file name by right-clicking the file , and choose "Properties". The full file name is in the "Resource" pane, on the "Location:" line, and can be marked and copied directly. You can then use that as a filename to open in your favorite editor and do the changes you need in there.

After editing, Eclipse should update the contents automatically. If not, right-click the file and choose Refresh.



来源:https://stackoverflow.com/questions/3721670/in-the-eclipse-text-editor-how-can-i-reformat-fill-justify-a-paragraph-to-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!