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 to 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 onEditor
item > Select Toggle Word Wrap - Alternatively, You can use the shortcut key
Alt + Shift + Y
command. - It checks the word wrap option and divides 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 the same option Toggle the Word wrap option in the Windows> Editor menu.
- The `Toggle word wrap option 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 the default word-wrap 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 the workspace level in Eclipse.
Open the workspace folder
Open org.eclipse.ui.editors.prefs file located in {workspace}.metadata.plugins\org.eclipse.core.runtime.settings folder.
add word wrap.enabled property with the true value and saved it.
wordwrap.enabled=true
Restart Eclipse to reload and apply Word wrap to every opened file.
It is enabled and applies to word-wrap enabled by default in Eclipse.
How do I wrap lines in Eclipse to 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 is Shown to the user.
- Select
Java
>Code Style
>Formatter
- Select
Active Profile
toEclipse [built-in]
and click on theEdit
button as shown below screenshot.
- Select Line Wrapping > Change Maximum Line Width to 80( default is 120) as shown below screenshot.
It split the line into multiple lines after the 80th character.
It also limits line length to 80 characters for applying auto-formatting.