Why is word wrap not working on eclipse? - java

I'm currently using eclipse Mars and I'm trying to figure out how to enable word wrap so that when my lines are too long, it can go down to the next line. I tried going to
Preferences > Java > Code Style > Formatter
and I created a new eclipse profile then set the maximum line width to 50 under the 'line wrapping' tab. I applied the feature and clicked 'Ok'. I tried to test if it worked by writing a really long line of code and it still didn't wrap. What am I doing wrong?

Related

How to disable intellij auto change my code format?

When I edit the java source code, intellij will auto format my code besides the places I edit, how to disable that ?
In the latest IntelliJ Idea (2021.3), Auto formatting can be stopped for one or more file type by going to
Preferences -> Tools -> Actions on save -> Enable or Disable Reformatting action for one or more file type
For those of you who want to disable formatting just for some specific file(s), there is a way since 2018.3 (IDEA-97848).
Go to Settings > Editor > Code Style > Formatter and add your exclusion pattern(s).
I tried disabling trim trailing spaces in code formatting but this doesn't work for my file type '.erb'.
I added my file type '.erb' to selectively disable code inspection for this file type but this doesn't work in IntelliJ version 2016.2.4.
I locked my file after I had made the changes using the lock icon in the Status Bar and this finally worked!
In Preferences > Tools > Actions on save you have a definition
BUT that can be overwritten by the following one, so check in that order:
In Preferences > Editor > Code style > [language] uncheck reformat on file save.
Update: None of those worked for me, so I change my file, commit without save (DON'T save during commit to avoid data loss, you'll be prompted) and then CTRL-Z.
Your file is committed and saved but only with your changes.
FWIW, I'm using Scala, on IntelliJ Community 2021.2, with the Scala plugin.
In my case intellij was messing with all the spaces in the code.
So, I changed following settings :
Editor > General
You can disable IntelliJ IDEA's ability to format (and therefore auto format) specific file types, but it comes at a cost.
To disable :
Settings > Editor > File Types
Select the file type you want to have never formatted
change the extension to something you don't use - for example '*.styl' to '*.oldstyl'
Now, even if you tell IntelliJ to reformat one of these files it won't.
The cost is that you lose syntax highlighting and language support all together.
In my case for stylus files it was worth it.
IDEA kept removing tab characters in sections of code that I wasn't even working in. SUPER annoying and destructive.

how can i jump to a specific line in an editor when click a label in the treeviewer in jface/swt-eclipse plugin development

I'm doing an eclipse plugin project. I have realized a view by TreeViewer, which can read info from text and show them.
The treeViewer has several columns and one of which shows the specific line number in a file,
just like this:
java.lang.NoClassDefFoundError: Could not initialize class
de.toem.pattern.element.Elements at
de.toem.eclipse.toolkits.util.SelectionUtils.getElements(SelectionUtils.java:36)
I have no idea how to jump to the file when click the number, please help me..
You could look at the source of org.eclipse.jdt.internal.debug.ui.console.JavaStackTraceHyperlink which is the code called from the Console view when you click on a class name hyperlink in a Java stack trace. This understands how to find the class, open the Java editor and go to the line number.

eclipse JSP line wrapping

In Eclipse, I've setup the Java formatter to wrap lines only when they exceed 120 characters. I would like the same setting to be used when I format JSP files, but at the moment it wraps them when they exceed 90 characters, is it possible to change this?
Window - Preferences - Web - JSP Files - Editor. Click on the link for your kind of JSP (HTML or XML content), and adjust the line width.
Note in the latest version of eclipse you won't see the line width option in jsp files editor, instead this is covered by the line with setting in html files - editor menu
Window -> Preferences -> type HTML...You'll see "Editor" so in line width, enter the value as you need. Works for me on eclipse 2018-12 version

Turn off Eclipse formatter for selected code area? [duplicate]

This question already has answers here:
How to turn off the Eclipse code formatter for certain sections of Java code?
(13 answers)
Closed 9 years ago.
When I ctrl+shift+f up the project code, its doing its job just fine, everywhere.
But its messing the CSS, specially those filter parts and adding bunch of spaces.
Also how do I specify some portion of Java code to not be formated by that command ?
To prevent specific portions of Java code from being formatted, go to "Window > Preferences > Java > Code Style > Formatter". Click the "Edit..." button, go to the "Off/On Tags" tab and enable the tags. Afterwards, you can simply embed those tags in Java code to disable the formatting in-between them. If you don't change the default tags, something like this will do :
//#formatter:off
this.
portion.of(code
); // will not be touched by the formatter
//#formatter:on
but this will be
reformatted.
IIRC, this option only exists since Eclipse 3.6.
As for css code, if you have installed Eclipse WTP, go to "Window > Preferences > Web > CSS Files > Editor" and you will find some basic formatting options there.
You cannot configure the formatting at class level, but you can configure at the project level.
To do the configuration follow this path in eclipse
window->preferences-> java -> code style -> formatter
now select the configure project specific settings and do your changes.

Eclipse autocompletion problem

Just installed Eclipse Helios (Win7 64) and I'm having a strange problem. I type syso-Ctrl-Space which is expected to complete to System.out.println("") but it doesn't work! I searched the web for about an hour now, I set Preferences > Java > Editor > Content Assist to defaults, nothing. Everything else seems to work. Ideas?
To be clear: the shortcut works, it completes everything except "syso" as seen so far, on syso (also tried sysout) it says "No Default Proposals". I couldn't find this kind of shortcuts in the Content Assist, but I set them to default anyway.
If you still cant get auto-completion working,try enabling the Template proposals under Content assist menu.This is the exact location,
Windows->Preferences->Java->Editor->Content Assist->Advanced
And make sure you have only one entry for syso(Under Templates menu).
I believe the right template is "sysout" and I believe this can be configured somewhere but could not tell you where. Try sysout and then Ctrl+Space
It's a template, you can find all templates under
Window -> Preferences -> Java -> Editor -> Templates
There you can see that the template name is "sysout" this will then trigger the string substitution for System.out.writeln() but you can change both the template name (if you prefer syso) and/or the actual code produced by invoking the template
Cheers
I am using Eclipse Galileo and had the same problem. Even after trying the above proposed solutions but it didn't work. After making the below change it finally comes out.
Go to Windows->Preferences->Java->Editor->Templates
Select sysout template and edit it.
Change the context from Java statement to Java.
And it worked for me. I hope this will be helpful for you.
As Peter stated, it is under Window -> Java -> editor -> templates.
Look for the line with the following values.
sysout "Java Statements" "Print to standard out" "on"
the preview should be as follows...
System.out.println(${word_selection}${});${cursor}
Your cursor needs to be located in a place where it would be legal to get that line. If your cursor is within a method definition and you type syso you will get the replacement. However if your cursor is in the portion of the text outside of any method definition, say where you declare variables for your class for instance, then syso will not suggest the illegal line system.output.println();.
I had this problem, read all the answers here, became convinced that it MUST be working in my copy, and realized I had been typing syso BELOW the closing } of my last method instead of in the method.
Eclipse on!
You may try to set the shortcut of Content Assist with ALT+L, if it works, then you can choose your favorite shortcut again. (The shortcut Ctrl+Space conflicts with the shortcut of switching input method). In eclipse on linux, the shortcut of Word Completion is ALT+/, so if you set this as the shortcut of Content Assist it also conflicts.)
Just go to the below address:
Windows->Preferences->Java->Editor->Content Assist->Advanced
and click restore default..........that's all
its work like a charm again.
Also check in this eclipse menu:
Windows -> Preferences -> Java -> Appearance -> Type Filters
If you see java.* or javax.* here then try removing it (or Restore Default will do the job) and see that works, it did for me.
Just found the solution for Eclipse Luna: write syso and press CTRL+Space and click on "enable intelligent code completion" and you are set.
I am sure you can find it somewhere in the options as well but this way it is fast and easy!
DIRTY WORKAROUND:
You can try out the following AutoHotkey-Code if you're still struggling like I am (STILL haven't been able to fix it myself)
#persistent
#ifwinactive ahk_class SWT_Window0 ; eclipse java
:*:syso::
sendraw System.out.println()`;
loop, 2
send {left}
return
#ifwinactive
You need to write this in a .ahk file and run it (AutoHotkey needs to be installed). You might wanna put this file into your startup folder. It's a very useful tool, you might wanna expand it one day.
You might have overlapping shortcuts.. Goto 'Overview' than the 'Keys' subsection. Type "ctrl +space" in the 'filter text' section. You should see the "content assist" and probably another command with the same shortcut. If another shortcut does exists, change its shortcut to something else.

Categories

Resources