Changing editor tab width in eclipse 3.5 - eclipse

I am trying to adjust the width of tabs from Window -> Preferences -> General -> Editors -> Text Editors where there is a field for "Display Tab Width". But no matter what I enter there the size of indentations when I start a newline in a Java file is 4. Any ideas?

Java files have a special place to edit this setting. You need to go to
Window -> Preferences -> Java -> Code Style -> Formatter
And edit the profile.

Changing Window -> Preferences -> General -> Editors -> Text Editors tab preference is relevant for text files, not for java files as indicated here. You may create a text file in Eclipse and check that your tab size is really changed.

Check your Java->Code Style->Formatter settings, to see whether you're using tabs or spaces; you might be using spaces!

This setting is superseded for Java by the setting from the Code Style Formatter.
It can be found in Java / Code Style / Formatter (click Edit) / Indentation tab / Indentation

How to set tab size (number of spaces when you press Tab) in Eclipse or Eclipse CDT:
There are multiple places to check and things to do:
Global Preferences:
Window --> Preferences --> General --> Editors --> Text Editors --> change "Displayed tab width" from 4 to 2
Window --> Preferences --> Java OR C/C++ [depending on which you're using] --> Code Style --> Formatter --> click "Edit" button for your "Active profile" --> click "Indentation" tab on top-left --> change "Indentation size" to 2, "Tab size" to 2, and "Tab policy" to "Spaces only".
Project Preferences (these override the global settings for a given project):
Project --> Properties (or just right-click on project in the folder list at the left, and go to "Properties") --> Java OR "C/C++ General" [depending on what you're using] --> Formatter --> either uncheck the box for "Enable project specific settings", OR check that box and ensure your settings are correct (refer to 1.2 above, beginning with the click "Edit" button step, but do it from this menu this time).
To test your new settings: return to your editor and press Enter with the cursor sitting immediately after an opening curly brace ({) somewhere. It should go to a new line with the proper indentation you've set above.
NB: watch out! If you press Enter on or after a line with different indentation from what you've set above, it will duplicate that wrong indentation (by copying the style of the lines just above) rather than accepting your new indentation settings. Do NOT think it isn't working in this case! It IS working! Just delete all of the old indentation and press Enter right after a { and you'll see everything works just fine.
Version tested: All tested in Eclipse IDE for C/C++ Developers, Version: Oxygen.3a Release (4.7.3a).
Duplicate or Related Questions & Answers:
Google search for "Eclipse change tab size" - https://www.google.com/search?q=eclipse+change+tab+size&oq=eclipse+change+&aqs=chrome.0.69i59l3j0l3.2483j0j4&sourceid=chrome&ie=UTF-8
https://superuser.com/questions/462221/how-do-i-reliably-change-the-indentation-width-in-eclipse
Eclipse tab width not changing
Also Related
Set line width vertical bar marker / print margin - Is there an Eclipse line-width marker?

After digging into this more deeply, I think I've figured this out:
Java file tab DISPLAY width
Confusingly, this is under "Formatter" in preferences (like the accepted answer says). But this is inconsistent location-wise with where the option for tab display width for the non-java file Editor is located.
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.indentation.size=16
Text file tab DISPLAY width
/instance/org.eclipse.ui.editors/tabWidth=2
I emphasize DISPLAY because this is just for rendering in Eclipse. It does not change the contents of your file, and has no effect on "Source -> Format".

Related

How do I change the font size of the menus that activate for right clicks in STS 4?

I'm using SpringSource ToolSuite 4. Although I have found you change change many font sizes in the Preferences -> General -> Colors & Appearances section
I can't find a place where I can modify the font size of the menus that appear in the IDE when you right click on an item (for example, the menu that pops up when you right click your project name and then select "Run As")
Where is this setting located?

Eclipse: Configure tab view

Is there a way to configure Eclipse to not use white spaces, BUT to still only indent 2,3,? spaces instead of the standard 4? I don't want to move to white spaces instead of tabbing, because I believe this is a personal choice for the person working on the project.
The closest answer I've seen is https://stackoverflow.com/a/2477132/5525659
It works, but I'm wondering if there is a better/easier way if people are sharing files different ways?
Any insights are appreciated.
You can change the displayed tab width in Window > Preferences: General > Editors > Text Editors.
In Java, the displayed tab width can be set in the formatter profile: Window > Preferences: Java > Code Style > Formatter, in the profile dialog, in the Indentation tab, in the field Tab size.
Other editors might use the text editors preferences or have their own preferences.

Cannot highlight all occurrences of a selected word in Eclipse

I tried using the Toggle mark occurrences (Alt + Shift + O) button and also in Preferences -> General -> Editors -> Text Editor -> Annotations and setting the C/C++ Occurrences and C/C++ Write occurrences. But still when I select a word it won't highlight all occurrences of that specific word.
What I am using is Eclipse Indigo Service Release 2 in XP, with a C++ project.
You can try to activate Toggle Mark Occurrences with icon on Toolbar:
Preferences --> Java --> Editor --> Mark Occurrences
In General > Editors > Text Editors > Annotations
Check out options that are checked in Preferences -> Java -> Editor -> Mark occurrences. Then restart Eclipse.
Find the Preferences under Window,
In General > Editors > Text Editors > Annotations(1)
(5) is to select the color and press apply.
The standard "Mark Occurrences" functionality included in Eclipse that everyone recommends only highlights identifiers in editors of whatever language. For example, it won't highlight int in C editors, and it won't help at all in the Console pane.
So if you want to highlight ALL occurrences on ANY word in ANY Eclipse pane (kinda like Notepad++ does), try the Glance plug-in for Eclipse.
As of November 2017 Glance works for Eclipse Neon and Oxygen. There was a period of time in which Neon was unsupported, and a fork appeared, but it seems unnecessary now (and abandoned).
There are two ways to highlight all occurences. First is using Eclipse options, which is not very reliable, because in many versions of Eclipse it is not supported.
Second is using a plugin called Glance which is available in Eclipse marketplace. This is supereasy and effective.
First Method
In the toolbar, there is button for Toggling Mark Occurrences. So, once you selected the text/word whose occurences you wish to highlight, then click this toggle button.
Let's say this step doesn't work for you. Then, Follow this step:
Goto: Window ==> Preferences ==> General ==> Editors ==> Text Editors ==> Annotations ==> On right Annotations types box: Occurrences ==> Select all check boxes.
You can also go to Window ==> Preferences ==> Java ==> Editor==> Mark Occurrences ==> Check all the checkboxes.
Restart Eclipse and check if highlighting works.
If still doesn't work, then Go to Second Method
Second Method
From Eclipse marketplace, install Glance. Once installed, restart Eclipse.
Now select any word in your eclipse editor
Move focus to component where you want to search
Open Glance using Ctrl + Cmd + F shortcut on Mac or Ctrl + Alt + F on other platforms
Enter text you want to search
Use Enter or **Shift + Enter** to find next/previous match
Close search box using Esc
You can also customize Glance from Window ==> Preferences ==> Glance
For Eclipse Mars:
Window --> Preferences --> Check (Mark occurrences of the selected element in the current file.)
As shown if figure:
Go
Java> Editor > Mark Occurrences
Uncheck "Keep Marks when the section changes" then click Ok
Restart Eclipse.
This work for me.
If you go into the window-prefrences, select the language you want/are working with. Select the editor under this specific language and then there is a mark occurrences there that has some options. Where it says keep marks when the selection changes, for me this was checked. When I unchecked it the system started highlighting correctly.
For folks who are using a dark background with light font colors, you may want to check out the highlight color in Preferences -> General -> Editors -> Text Editor -> Annotations. Mine was defaulted to black, which does not stand out on a black background.
Glance does not work anymore, but in current Eclipse Versions (Eclipse 2020) you can
highlight any word by selecting the word and pressing CTRL+F. The word is now highlighted. In the small search input, you can toggle 'match whole word' and case sensitivity.
I'd like to complement the other answers - which work in Java editor only or require plugins - with a way to highlight all occurrences of any text (not just a word or identifier) in any editor of text files (e.g. SQL, CSV, HTML, TXT, Java, etc ...).
There is a standard/built in command called Find Text in File (under Window -> Preferences -> Keys)
By default it has no keyboard shortcut assigned. Simply give it a shortcut (e.g. Ctrl+Alt+S) select some text (not necessarily a word) and it will find and highlight all occurrences of that selected text.
It can also be invoked from the menu as Search -> Text -> File.
Enjoy 🙂
Click the word and hold until a popup appears as shown in the figure.
On the popup, there is a little right arrow, after clicking it, a new icon shows up.
Click that link to open preferences.
Once in preferences, select C/C++ Occurrences (it will be language specific) and select Include in next/previous navigation with Text as Highlighted.
This should enable the feature of highlighting all occurences of the selected word in the opened file.

Configuring tab space for Eclipse Compare Merge editor

Is there a way to configure tab spaces for Eclipse Compare/Merge editor?
I have the Text Editor to use 2 spaces for tab and "Insert spaces for tabs" but this doesn't seem to take effect in the Compare/Merge editor. It's quite annoying since it's occasionally messing up the indentation in the source code. I guess my other option is to use an external tool but it would be great if this can be configured within Eclipse.
I'm using Indigo SR2 (64-bit)
--
This appears to be a related Eclipse bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=259410
You can choose to ignore whitespaces in the compare editor. Either you right click in the editor and choose Ignore White Space or you set this in eclipses preferences Window -> Preferences -> General -> Compare/Patch -> Ignore White Space

Eclipse whitespaces for tabs

I'm using Galileo, and I've gone:
Preferences -> General -> Editors -> Text Editors -> Spaces for tabs
but the editor still inserts real tabs when I press the TAB key. This is driving me crazy. How do I force eclipse to put in spaces for tabs? I'm editing Java files.
Thanks
What about :
Window > Preferences > Java > Code Style > Formater
and, then, edit the formating style (it'll open another dialog)
In that new dialog :
General settings > Tab policy => choose "Spaces only", instead of "Tabs only"
You can also set the "Tab size".
Go to Preferences -> Java -> Code Style -> Formatter.
Click edit next to your active profile.
Change your tab policy to Spaces Only