Replace spaces with tabs using Eclipse - eclipse

I downloaded some code from the Internet, and the four-space indentation is bugging the crap out of me. I tried to do a find and replace for "<4 spaces>" and replace it with "\t", but that just replaced all sets of spaces with the string "\t". How would I put a tab in the "replace" box?

Open Window->Preferences from menu bar.
Select Text Editors from tree menu.
Uncheck Insert spaces for tabs.
After that, run Format menu from context menu and save the file:

I figured it out. I just check the box that says "use regular expressions", then use \t.

In answer to the second half of your question:
The reason why people like spaces more than tabs is consistency. If you have your editor set to show tabs as 4 spaces wide, and I have my editor set to show tabs as 8 spaces wide, the code we're writing will look different to each of us. That's okay until our mutual coworker forgets that we're using tabs and starts spacing his lines using 4 spaces. Now his code looks fine to you, but all the indentation is off to me.
Also, what happens when our work decides that lines should be 80 characters long, or 120 characters long? You'll happily code with 4 space tabs, and when it gets to my editor, I suddenly see some of your lines as too long.
Generally, it doesn't matter whether you use spaces or tabs, as long as you (and every person who works on your code) agrees on which to use, and how wide a tab character is.
I use 4 spaces everywhere, because it looks the same on every editor, every repository, when cated, and everywhere else.

Kouhei response is in the right track, but you'll need to change the options of the Java formatter if you want the auto formatter to use spaces (in the preferences, look for Java -> Code Style -> Formatter, create a new style from one of the existing one, and choose "always use spaces"). Then, Ctrl + Shift + F will remove the tabs and insert spaces.

To resolve the issue of tab with space in the Eclipse editor:
Menu Window --> Preferences --> Java --> Code style --> Formatter
Click on configure project specific settings.
Choose the project
Check Enable project-specific settings
Click on New
Mention your profile name --> click OK.
The profile page will be popped up
Choose Space only under tab policy label of the indentation tab.
Click apply and the OK.
Use Ctrl + Shift + F to format a Java class which will replace tab with space.

Eclipse Helios for C++ developers
Instead of changing the default text editor, change the Code Style/Edit -> see pictures

Related

Eclipse string literal line wrapping

When I run the Formatter it indents string literal lines all the way to the last line of the variable name, even if that exceeds the column guide, as shown in this screenshot:
Ideally, I want all of the lines to be wrapped similar to the way the first line is wrapped, with just a couple of tabs (or 1 tab if possible). I've changed all the Formatter settings for assignment and binary expression and it doesn't affect the Formatter's line wrapping behavior.
Is there a way to make Eclipse wrap lines like NetBeans or maybe with some plugin?
Here's what my Formatter settings are for Line Wrapping:
Plugins
Eclipse Colorer
has an "Enhanced and fixed word wrapping mode".
Eclipse Word-Wrap
is dedicated to word wrapping and might do the job.
Customization
Here's how and where you do it in Eclipse: Preferences->Java->Code Style->Formatter, then click the Edit button and select the Comments tab. After that, the same place, you can select the Line Wrapping tab and the Indentation tab. You can also set margins and tab sizes in Preferences>General>Editors>Text Editors by editing the Displayed Tab Width
I'll note that the Eclipse version should be Eclipse Project Neon (4.6) M4 or higher because Eclipse 4.6 came with some updated word wrapping out of the box.

Egit detects tab chars as changed

I'm using Eclipse + EGit, and every time I make a commit, Egit detect tab chars as changed:
but I don't change anything on that part of the code. Tab chars are tab chars, and are not replaced by whitespaces.
Any idea ?
You may have some auto formatter active, which replaces tabs by blanks or the other way around. This may not really be visible in the editor on first glance, as the editor can display a tab character the same as the respective number of blanks. You may want to store the original file and the edited one separately outside Eclipse to compare them in another editor.
However, you can ignore whitespace changes in the compare view at least. I'm not sure of your version, for me that is a toolbar button in the main toolbar. You can press Ctrl-3 and enter "Ignore" to see, if that command is available for you.

Aptana tab indentation guides

I recently moved from geany to Aptana as I'm working on some bigger projects and felt I would benefit from a full IDE.
One feature I'm really missing is the little grey line every four spaces to help me maintain indentation consistency. Does anything like this exist for Aptana/Eclipse?
get the PDT tools Indent Guide plugin
Under
Preferences -> General -> Editor -> Texteditor you can activate "Show whitespace characters". If you click on "whitespace characters", you can define, which character should be displayed. Here you can active "Tabs". It's not as good as the lines from Notepad++, but better than nothing.
You can set a print margin indicator (vertical line) in Preferences > General > Editors > Text Editors - but this would only be a single line. You could use tabs instead of spaces - there are options to insert spaces when you use the Tab key. In this same menu, you can choose to show whitespace characters, which will help keep your spacing in order. I don't know of any grid options.

How do I turn off Tab and New Line markers in Eclipse?

I am using Adobe's ColdFusion Builder, an Eclipse-based IDE built on top of Aptana.
All of a sudden, I am getting a type of whitespace marker showing in my Eclipse Editor. I must have accidentally hit a key combination.
Here is a screen dump.
I have already tried "General > Editors > Text Editors > Show whitespace characters" and it is not this. I already have show whitespace characters turned off. If I turn it on, then the Whitespace Characters display over the top of what I am already seeing.
Can anyone tell me how this can be turned off? Most annoying.
Many Thanks
It's under Preferences -> General -> Editors -> Text Editors
Just uncheck 'Show Whitespace Characters':
Did you try Restarting Eclipse? If that didn't work, you might try this http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka11640.html which explains which file to delete to force eclipse to revert to use default settings.
I have done this several times by accidentally hitting some keystrokes.
If you go to Windows/Preferences/General/Keys you will see all the keyboard shortcuts you have.
Mine is set to Control + .
(that's a period by the way) I had to place my cursor inside the document and do it a couple of times to make it work because there is also a keyboard shortcut for Control +
On a Mac it is Cmd +.
Hope that helps.

Change Eclipse tab to correctly indent line as Emacs does

In Emacs when I hit tab anywhere on a line, the line will indent correctly (or at least to the mode settings). When I hit tab again it will move back to the next block. When programming Python this really helps since closing a block is done by lowering the indention level.
Is there a way to configure Eclipse to do the same?
Currently, I have to erase the leading white space then hit tab.
This question is a reposting of a superuser question.
Try ctrl-i (Cmd-i on osx) to indent the current line or a selection inside eclipse (if you're using default key binds as opposed to emacs). Or, if you want a different key bind, go to Appearances > General > Keys and change the bind for Correct Indentation to key(s) of your choice
In Eclipse, go to Windows -> Preference -> Java -> Formatter.
In Active Profile drop down box, select any profile, click Edit on right of it.
In Profile Dialog box opened, you can change a lot of things like Indentation, New Line, Braces, White Spaces etc.
Alternatively, if your profile is altogether different than standard one, Create a new active profile and then edit it accordingly.