Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 306
Simon Avatar asked Sep 15 '10 20:09

Simon


3 Answers

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).

like image 199
lashtal Avatar answered Nov 09 '22 13:11

lashtal


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...

alt text

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.

like image 1
VonC Avatar answered Nov 09 '22 13:11

VonC


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.

like image 1
Michael-san Avatar answered Nov 09 '22 12:11

Michael-san