On the editor window, ‘Word Wrap’ is a text feature that allows you to limit text content to a specific width. It is a basic feature in any Text editor.

Even though Eclipse is a Source Code IDE editor, It supports word wrap out of the box.

The user will have to scroll horizontally to see the content if you have a long line of text on a single line.

For example, The text is divided across multiple lines with word wrap enabled, and the content is limited to fit within the code window.

How do I enable text wrapping in an Eclipse?

There are multiple ways, we can enable and disable the word wrap in Eclipse. One way is, Enable it at the file level.

  • Open Eclipse IDE
  • Select and open the file that you want to apply word wrap
  • Go to Window Menu > Click on Editor item > Select Toggle Word Wrap
  • Alternatively, You can use the shortcut key Alt + Shift + Y command.
  • It checks the word wrap option and divided the long text content into multiple lines, and the user can see the content without scrolling sideways.
  • Once this option is enabled, It shows the selected icon and applies to all tabs in the Eclipse editor.
  • You can also disable it by clicking again the same option Toggle Word wrap option in the Windows> Editor menu.
  • Toggle word wrapoption is not visible for clicking on without the file opened in the code editor.

This approach only works with the specific file opened in the code editor.

If you open a new file in the code editor, This option is set with default word-wrap with disabled.

Eclipse enables word-wrap default

It is a way of enabling word wrap by default and It applies to all files opened in eclipse.

Eclipse does not provide UI to enable word wrap by default.

There is a way to set it globally with workspace level in eclipse.

  • Open workspace folder

  • Open org.eclipse.ui.editors.prefs file located in {workspace}.metadata.plugins\org.eclipse.core.runtime.settings folder.

  • add wordwrap.enabled property with true value an d save it.

    wordwrap.enabled=true
    
  • Restart eclipse to reload and apply word wrap to every opened file.

It is enabled and applies to word-wrap enable by default in Eclipse.

How do I wrap lines in Eclipse limit maximum line length

Word wrap feature limits the based on window maximum width.

Let’s see how to wrap lines with a maximum count of characters.

This example split the line into multiple after 20 characters.

Here are the following steps

  • Go to Window -> Preferences Menu item,
  • Preferences window Shown to user.
  • Select Java > Code Style > Formatter
  • Select Active Profile to Eclipse [built-in] and click on Edit button as shown below screenshot.

Eclipse java formatter line length limit

  • Select Line Wrapping > Change Maximum Line Width to 80( default is 120) as shown below screenshot.

Eclipse line wrap with auto format

It split the line into multiple lines after the 80th character.

It also limits line length to 80 characters for applying auto-formatting.