Eclipse: use both tabs and spaces for indentation - eclipse

A project I'm working in has an indentation standard as follows:
A single tab-width is 4 space characters.
A double tab-width is a tab character displayed at 8 spaces wide.
Examples:
A singly-indented line begins with four spaces
A doubly-indented line begins with a tab character
A triply-indented line begins with a tab character followed by four spaces
A 4x indented line begins with two tab characters
...and so on
In Vim, the necessary configuration is achieved with:
:set tabstop=8 softtabstop=4 noexpandtab
How can I configure Eclipse to automatically enforce this indentation standard?

I don't believe Eclipse CDT supports this indentation style.
Eclipse is open source; you could consider contributing a patch to add support for this style.

Eclipse doesn't have that built-in, but it looks like the plug-in Vrapper (Vim) provides what you are looking for.
See Vrapper > Documentation > Configuration:
softtabstop - When using spaces for tabs, set this to the number of spaces inserted for each Tab key press and hitting
Backspace in InsertMode will delete that many spaces as if you had
deleted a tab character.
tabstop - Used by i_ctrl-t, i_ctrl-d, and :retab. Determines number of spaces to replace each tab character with when xpandtab is enabled.
expandtab/noexpandtab - Used by i_ctrl-t, i_ctrl-d, and :retab. Determines whether :retab should replace all tabs with spaces (true) or spaces with tabs (false). Also determines whether i_ctrl-t and i_ctrl-d will replace tabstop spaces with a tab.

Eclipse does support this natively.
My eclipse version:
The result (see in-image comments):
Step 1:
Step 2:
Step 3:
Step 4 (the most important step):

Related

Netbeans 12 "diff window" does not always highlight added or removed spaces in the code

I upgraded Netbenas 8 to Netbeans 12 and now my diff window does not always highlight added or removed spaces in the code.
It does highlight if spaces was added or removed in the middle of the line (after a non space character), and before a non space character.
But it does not highlight when the space was added or removed form the beginning of the line, or at the end of the line. Preceding and trailing spaces change does not get highlighted.
I tried restarting Betbeans - it did not help.
I checked HTML, PHP, TXT source code, all have the same problem.
Is there any config parameter to fix it, or is it a bug?
Navigate to Tools > Options > Miscellaneous > Diff
By default, the checkbox Ignore Leading and Trailing White Space is checked:
Just uncheck the checkbox, then click the OK button. Diff will then report on leading and trailing space differences.

indeneted files in my sublime don't show up indented correctly on github files

I have indented my files in my sublime text but when I push to github they don't look indented. How do I fix this?
The approach taken to indent file on sublime is:
select the code > Edit > Line > Reindent
looks like this on github:
Your issue looks to be caused by your use of literal tab characters for indenting as opposed to using spaces instead.
If there's a hotter holy war topic among developers than the debate of tabs versus spaces, it's probably related to how wide you should interpret a tab character to be for display purposes if you happen to use them.
In particular your images would appear to indicate that you think that tabs should be 2 characters wide and GitHub thinks they should be 8. As mentioned in this answer you can append an extra query field to the URL in GitHub in order to view the files the way you prefer them to be viewed.
As far as I'm aware that just changes how they're rendered on the page when you view and doesn't actually modify the file at all. If it's important that the file retain the same indent levels regardless of where or how you view the file, you should convert from tab indentation to space indentation instead since a space is unambiguously sized.
If you're using Sublime Text you can do that by clicking in the status bar where it says Tab Size: 2 and select Convert indentation to spaces; the status bar will switch to say Spaces: 2 to indicate that the indent has changed.

Number of spaces in Tab - OpenEdge

In OpenEdge the tab can be configured to any number of spaces, usually is configured to 4 spaces.
To insert a tab in a text can be used: ~t.
What I want to find is how many spaces have the tab set.
For example, I am reading a file line by line, and for each line I want to see how many spaces are at the beginning.
I am using:
iNoOfBeginningSpaces = index (cLine, left-trim (cLine)) - 1.
But if the line begins with 3 tabs then it gives me 3, and not the number of the spaces: 3 * spaces from tab.
Is there a way to find the number of beginning spaces of a line, treating the tab as x numbers of spaces?
No. Spaces and tabs are not the same thing. You are getting confused by the fact that programming editors, word processors and printers convert tabs to spaces to get to tab stops. But in a data file no such conversion occurs (unless you are saving the file from an editor that does such conversions).
I will tell you how to check in your AppBuilder.
On the AppBuilder Menu you go to OPTIONS and then EDITING OPTIONS and there you can set how much "spaces" the editor uses for Tabs and Syntax indents. But this is basically for DISPLAY purposes within APPBUILDER.
Tom has given you the correct technical answer, a tab is a type of control character that can be interpreted differently by different apps. It has a different value than spaces.Below you can see the value of space and Horizontal Tab.
Char Oct Dec Hex Control-Key Control Action
HT 11 9 9 ^I Horizontal tab, move to next tab stop
=============================================
Char Octal Dec Hex Description
SP 40 32 20 Space

Can NetBeans remove trailing whitespace and change tabs to spaces on save?

I just started to use NetBeans, and am trying to work out how to:
Make it so that trailing whitespace is removed on save. I know that you can invoke it manually, but it’s annoying if you forget. Can it be done automatically on save? I want this done because it keeps the code neat, because it’s really annoying when you’re moving through code and the text cursor goes all over the place because of trailing whitespace you don’t see, and because trailing whitespace has unintended effects on HTML layouts and other stuff.
Make it so that tabs are automatically made into 4 spaces while you’re typing rather than converting on save, or, worse, only when manually invoked.
For the first question, NetBeans 7.0+ has now a built-in solution. You can find it in:
On NetBeans 7:
Tools > Options > Editor > General > When saving files > Remove Trailing Whitespace: Never / Always / For Modified Lines Only
On NetBeans 8 / 9:
Tools > Options > Editor > On Save > Remove Trailing Whitespace From: None / All Lines / Modified Lines Only
[Original] For your first question, how to set NetBeans to remove trailing whitespace, the answer is that there is no setting (at the moment) to control that. It happens automatically, but not to every line. Whitespace is only removed from the lines you edit (or from the entire file if invoked manually). See Petr Pisl's blog entry titled "Removing trailing spaces" for a more complete explaination. (Note that even though he is blogging about NetBeans' PHP features, this particular feature applies to the basic editor shared by all NetBeans supported languages.)
[Update] This feature has been made available as of version 7.0, as pointed out by others in comments and answers below.
For your second question, set the editor to automatically make tabs into spaces as you type, you can find that setting in the Editor Formatting options:
Click on the Tools menu, and choose Options
Click on Editor in the top row of icons
Click on the Formatting tab
In the Language field, ensure that All Languages is selected
In the Category field, ensure that Tabs And Indents is selected
Check the box for Expand Tabs to Spaces
For each additional language that is available in the Language field, check that either Override Global Options is not checked, or that Expand Tabs to Spaces is also checked for that language.
Click OK
That will make sure that when you hit the tab key the specified number of spaces is inserted rather than a tab character. As above with whitespace removal, any existing tabs in the file are left as-is unless you invoke the manual command to change the entire file. (Moreover, even if you edit a line with tabs on it--leaving the tabs in place--the editor will not convert them to spaces. Only new instances of hitting the TAB key are controlled by this option.)
Tools > Options > Editor > On Save > Remove Trailing Whitespace From: None / All Lines / Modified Lines Only
This is as of Netbeans 7.3, according to Webmut.
For netbeans 7.4+
Windows - Tools > Options > Editor > On Save > Remove Trailing Whitespace From: None / All Lines / Modified Lines Only
Mac - Netbeans > preferences > Options > Editor > On Save > Remove Trailing Whitespace From: None / All Lines / Modified Lines Only
Also you can set this as language specific.
You can also set reformat while saving.
if you want to remove all trailing spaces in the file manually ONLY ONCE, you can invoke action 'Remove Trailing Spaces' from Source menu manually.
Source -> Remove Trailing Spaces

Is there a way to get Eclipse to treat 4 spaces exactly as it treats a tab?

I understand how to get Eclipse to insert spaces in place of tabs, but then I'd rather not have to arrow through 12 spaces to reach an indented block.
Bonus points if there's a way to hide the spaces from the 'show whitespace characters'. I like to see whitespace characters for tabs and carriage returns, but the display gets too cluttered when spaces are also displayed.
Try CTRL+[right,left] arrow key. Certainly one of my most-used combos.
As it turns out, this appears to not be possible in Eclipse.
With the next Eclipse 20199.12/4.14, that might actually be possible! (albeit ten years later)
See "Backspace/delete can treat spaces as tabs"
If you use the Insert spaces for tabs option, now you can also change the backspace and delete keys behavior to remove multiple spaces at once, as if they were a tab.
The new setting is called Remove multiple spaces on backspace/delete and is found on the General > Editors > Text Editors preference page.