Egit detects tab chars as changed - eclipse

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.

Related

Weird characters appeared in Netbeans

I was creating java classes in netbeans, and I don't know what button I pressed to make points for placeholder followed by the paragraph markers (ΒΆ) appear in my code.
How can I proceed to make them disappear?
That's what it looks like at the moment
Try view > Show Non-Printable Characters
Go to 'View' and uncheck the Show Non-Printable Characters. That will clears off your problem
View -> Show Non-printable Characters

GitHub markdown tab size

A little confused at the purpose of the "tab size" in GitHub's markdown editor. When changing the value in the dropdown, it seems to have an effect in the "Edit File" tab but not the "Preview" tab. Nor does it have an effect after saving.
Bottom line, I'd like my tab size to be 2 when displayed in my repository readme, instead of 8 which makes the markup seem disorganized.
Thanks for your help.
You need to manually convert all the existing tabs to spaces in the document.
Changing the setting in your editor/IDE or on GitHub (to use spaces) does not change any existing text in the document. It only affects any new text you add to the document. If the existing content includes tab characters, you need to convert those to spaces for consistency. While you would need to manually change each instance on GitHub, your local editor/IDE should have a function to do that document wide from a single command (usually called something like "convert tabs to spaces").
By way of explanation, when a tab is inserted in a document, all that happens is a tab character is inserted. No information is included indicating how wide that tab character should be. Each document viewer will have its own setting indicating how wide a tab character should be and if those settings do not match, then the document will display differently in each context. For example, the GitHub editor can be configured to be different that the default. However, the rendered preview does not have any settings so you only get the default tab wide (8 chars on GitHub).
For that reason, most editors/IDEs include a setting to insert spaces when you type the tab key. That insures that every tab is exactly the same width across all viewers anywhere. However, the "spaces" feature of editors works by intercepting the press of the tab key on your keyboard and replacing the tab with the set number of spaces. Therefore, actual space characters get inserted into your document and there are no tab characters (the editor hides this by also intercepting backspace key presses). The important thing to note is that this feature works by intercepting and altering key presses on the keyboard. Therefore, it has no effect on text already in the document. Which is why you need to convert the existing text. Fortunately, the "convert tabs to spaces" feature of most editors/IDEs will use the tabs/spaces settings when doing the conversion, so running that command once should fix the entire document as long as your settings are configured properly.
Most editors/IDEs also have a "show whitespace" (or "view whitespace)" feature, which can be used to confirm the conversion was done properly. When "show whitespace" is turned on, tabs display as an arrow and spaces as dots (usually a lighter gray than the surrounding text). If you have converted your entire document. you should see no tab arrows anywhere, only dots for spaces. Once you are satisfied that no tabs exist, you can then turn "show whitespace" off. Unfortuntely, GitHub's online editor does not offer this feature, so you'll need to use your local editor.

Replace spaces with tabs using 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

Eclipse stops me from adding superfluous tabs

I was editing a fairly extensive ant xml build file file and tried to add in an extra tab where I thought appropriate. As it happens, the tab shouldn't have been there (if we were following some "rules" on What Looks Pretty In XML).
And as it happened, eclipse refused to let me put the tab there. I tried a few times, and sometimes it would "allow" one extra tab, but v. often it would either
ignore the tab
remove a tab
I know that what eclipse is doing is "right", (in some byzantine sense, because this isn't python, it is an ant xml build file, so the only way it is "right" is from an aesthetics point of view) but I think it is "stupid".
How can i disable this "feature" in eclipse?
I assume you mean the tabulator key (as opposed to the sub-windows, that are also called tabs).
Look up your editor preferences. Things that might help are the settings "insert spaces for tabs", "displayed tab width" and "smart caret positioning at line start and end".
If this doesn't help, try to avoid the XML editor by not opening with double-click, but using "Open With .." -> "Text Editor"

Move Eclipse's Find/Replace dialog to a view?

I find Eclipse's (Eclipse 3.7, Indigo, running under Mac OS X 10.6.8) Find/Replace floating dialog box to be very annoying. Part of the time it ends up obscuring the search results. Is there any way to have Eclipse move the Find/Replace somewhere else? I'd like it to be a pop-up view, as I often do with the Console, Servers, Outline, and other views. However, if it could be incorporated into the view which it's searching, that would be great, too.
Eclipse's Find / Replace dialog is a dialog, not a view, so you can't drag and drop it to one of the view areas.
Here's a Eclipse search plugin that might work for you. Scroll all the way to the bottom of the page to get the Software Update link.
Worst case, you could write your own Eclipse plug-in that creates a view that does a Find / Replace.
TL;DR
Find/replace cannot be used as a view. Here are two ways to find text without obstructing the search:
Use incremental search (CTRL+J)
Use the quick search plugin (CTRL+SHIFT+L)
Pros and cons
Both approaches behave differently from the traditional find/replace and may require some getting used to.
Approach 1.
It works out of the box, no need to install a plugin, but it (currently) does not support pasting nor searching for the current selection (but there is CTRL+K for the latter). You can use UP and DOWN or repeat CTRL+J or CTRL+SHIFT+J to jump between matches.
Approach 2.
This still opens a dialog, but one which integrates the search results rather than obscuring them. I suggest resizing it to have a good preview size.
The default shortcut shadows the "Show Key Assist" original, but this can be changed. It is an extra install and AFAIK only supports case sensitive searches, but it supports searching for the selection and pasting.
It shows matches across files, starting with the top open editor (if you have more than one visible, e.g. side by side, it sometimes does not start with the one you were last on). You can move between matches with UP and DOWN and hit enter to go back to the editor on the selected match.
NOTE
I suppose on OSX you can replace CTRL with CMD in keyboard shortcuts above to achieve the same, but I could not test it. The shortcuts can be customized in Preferences->General->Keys