Indentation in Eclipse - eclipse

I am trying to indent my code in eclipse .
List<TestDB> list=session.createCriteria(TestDB.class).add(Restrictions.eq("testCase",testCase)).list();
I type my code as above and when I save my code the line is indented as follows :-
List<TestDB> list = session.createCriteria(TestDB.class)
.add(Restrictions.eq("testCase", testCase)).list();
I tried this from SO :-
How do I disable auto-indent in Eclipse Helios (Java)?
But it is did not help . Can anyone please help me with the indentation ?

Window -> Preferences -> Java -> Editor -> Save Actions -> Deactivate Perform the selected actions on save.
Also right click your project, select Properties and check the same setting here.

Related

Sublime Highlight when select characters

I'm using VSCode, and it has a nice thing to match characteres (without ctrl+f). Same as the image below.
Is there any plugin to sublimeText to do the same thing?
Thanks!
I was curious about this, so I've done some research:
There's a SublimeText plugin that does exactly what your are looking for:
SublimeText/WordHighlight can be easily installed via Preferences -> Package Control -> Install package -> WordHighLight (or the shortcut ShiftCtrlP -> Type Install package -> Type WordHighLight).
Once installed, when a word is selected, all matching words in the document are highlighted:
I've tested it successfully in SublimeText 3.
Don't forget to add
{
"highlight_non_word_characters": true,
}
...to your Preferences -> Package settings -> WordHighLight -> Settings - User in case you want to highlight partial words, as the sample you provided. Otherwise, only complete words are highlighted.

Netbeans remove line counter

It is possible to delete these method's lines counters:
I was looking in options and I haven't find any way to disable it.
To disable line counters go to:
Tools -> Options -> Editor -> Folding
At the bottom uncheck Show summary.
However there is no option to remove {...} entirely.
Tools -> Options -> Editor -> Folding

How to disable auto formatting upon save in Eclipse?

Eclipse keeps auto formatting upon save, for example: it is insisting the following code should be in a single line once I save, despite breaking it up the way I want to.
#Transactional(rollbackFor = DataAccessException.class, readOnly = false, timeout = 30, propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT)
Window > Preferences > Java > Editor > Save Actions.
Can also be configured at the project level. Project > Properties > Java Editor > Save Actions.
Absolutely maddening improvement. For if statements do the following:
Window | Preferences | Java | Code Style | Formatter | Control statements tab
Select Keep simple if on one line.
You might also try the Line wrapping tab
This is a Late answer, But just for novice to understand it clearly I have a snapshot of the setting.
Please follow the path on left.
And change highlighted setting.
If you wish to keep the auto-formatter, but don't want this behavior, you can also configure it in the fomatter :
right click on the project -> properties -> java code style -> formatter
(If you don't have a project specific formatter the global configuration can be accessed this way : Window -> Preference -> Java -> Code Style -> Formatter).
Edit... the active profile, open the Line Wrapping tab, and there check the Never join already wrapped lines option.
This way you can wrap lines wherever you want and eclipse won't remove your line breaks (which is a must if you wish to have readable lambda expressions), but keep the formatter active.
This option is there at least since eclipse Luna
Here is a screenshot where this option is :
Just wanted to add a tip. If you want to avoid the line wrapping you can simply increase the "Maximum line width" value to something enormous. As long as that is sufficiently high eclipse won't do any wrapping.
Preferences > Java > Code Style > Formatter > Edit > Line Wrapping > Maximum line width

Where to change highlight color for selected occurrences in Eclipse?

When a method or variable is selected it is highlighted in Eclipse with some color. Can anyone advice where to change that color? I'm working under Windows OS.
I've found where to change it:
Preferences -> General -> Editors -> Text Editors -> Annotations
and there you have to change both "Occurrences" and "Write occurrences".
Preferences -> General -> Editors -> Text Editors
Current Line Highlight
I think you want the above
else
Preferences -> Java -> Editor -> Syntax Coloring
Element -> Java -> Method or Variable
Check Enable and select color
This has made me mad for about half an hour.
If the issue appears in JavaScript files, the option is under Preferences -> General -> Editors -> Text Editors -> Annotations and in the Annotation types choose JavaScript Occurences. Mine was set to black, nasty little thing took me too long to fix.
If you're using eclipse with PHP package and want to change highlighted colour then there is slight difference to above answer.
Right click on highlighted word
Select 'Preferences'
Go to General > Editors > Text Editors > Annotations. Now look for "PHP elements 'read' occurrences" and "PHP elements 'write' occurrences". You can select your desired colour there.

Automatic indentation on Eclipse PDT when copy-pasting

This is a simple question :
Is there any automatic indentation alignment on Eclipse PDT when you do a copy-paste ?
Because it doesn't work on my installation (raw copy-paste), but maybe this is because I use tabs instead of spaces, so I want to know if it will work if I switch to spaces.
Thanks
Actually, such a function exists now for eclipse CDT. In preferences : C++ -> Editor -> Typing, "when pasting", "adjust indentation".
Perhaps it is the same for PDT ?
I don't know specifically about PDT, but normally you can indent code with Ctrl + i, and format code with Ctrl + Shift + f (under Preferences -> Java -> Code Style -> Formatter you can specify how the formatter should work).
You can even select multiple files in the navigator and select Source -> Format to format several files then.
Tony Vermeiren had a suggestion that worked for me
(from https://bugs.eclipse.org/bugs/show_bug.cgi?id=351771#c17)
open workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.php.ui.prefs
add "smartPaste=false" at the end
save & restart eclipse
A similar idea to Davids is the use of Save actions: in the Preferences selecting Java/Editor/Save actions you can define an action to format the java code files during saves. It would solve the paste format problems during the save.
If you manage codes with different coding standards, where this formatting might have problems, define multiple formats, on a per-project basis (using the Project properties window).
Ok then I guess the answer is : no, this functionnality doesn't exists yet. I've moved to PhpStorm and I'm more than happy.
TLDR: uncheck "C/C++->Editor->Typing->Adjust indentation"
Explanation:
When i copy paste the following:
And "C/C++->Editor->Typing->Adjust indentation" checked
The result is that the second line has unwanted indentation:
To fix this just uncheck "C/C++->Editor->Typing->Adjust indentation"