Configure eclipse so that backspace unindents - eclipse

Having eclipse configured to use space instead of tabs, is it possible to configure eclipse so that the backspace key unindents like the tab key indents?
A demonstration to clarify what I mean with backspace unindent (the vertical bar stands for cursor position and the dots for spaces):
if(bar == 0) {
|foo = 0;
}
Pressing tab will indent 4 spaces:
if(bar == 0) {
....|foo = 0;
}
Pressing backspace only goes back 1 space:
if(bar == 0) {
...|foo = 0;
}
What I want is that it goes back 4 spaces:
if(bar == 0) {
|foo = 0;
}

You know that "shift+tab" will outdent a line already, correct?
Hmmm, I just took a look at preferences->general->keys. I only see indent line there, no outdent (or anything useful under "dent").
Personally, I would say that backspace is the key I hit second most often, after space. Rebinding it would drive me bonkers.

According to these very similar questions:
In Eclipse, how can spaces behave as tabs?
Is there a way to get Eclipse to treat 4 spaces exactly as it treats a tab?
it seems to be not possible :(

The feature will finally be available for next version of Eclipse 4.14 planned for 2019-12
https://www.eclipse.org/eclipse/news/4.14/platform.php#delete-spaces-as-tabs
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.

Hard way: set Eclipse to format indention using the tab character. Then backspace will remove the tab char
Easy way: start using the formatting feature of Eclipse to fix the formatting. Ctrl-Shift-F will format the selected lines or the whole file if there is nothing selected, using the formatting rules you configure.
Alternative: select the lines of text you want unindented and use shift-tab, it will unindent the selected lines.

Related

VS code newline adding tab instead of spaces

I am having trouble finding a setting for new line spaces in VS code. Currently, I have it set up to a tab is the size of 8 spaces (after detecting indentation from content). This is because a principal software engineer edits in a different program, and set tabs to be 8 spaces, but code inside brackets were only indented 4 spaces.
Is there a way to set new lines following a bracket opening to tab only 4 spaces, but keep the rest of my tabs set to 8 spaces?
I've tried resetting tabs to only 4 spaces, but that changes the document as a whole and the indentation is off.
For example, when tabs are set to 8 (after detecting indentation from content), this is what it looks like (I added a comment to show where hitting a new line brings the cursor to):
if ((access(LOGFILE, F_OK)) != -1)
{
if(remove(LOGFILE) == -1) // Remove the older file
{
//this is where the newline starts
printf("Unable to delete the older log file.\n");
return ERROR;
}
}
Whereas, when I set tabs to 4, this is what it looks like (if statement indentation is bad):
if ((access(LOGFILE, F_OK)) != -1)
{
if(remove(LOGFILE) == -1) // Remove the older file
{
//this is where the newline starts
printf("Unable to delete the older log file.\n");
return ERROR;
}
}
Is there a way to change it so I can use the 8 tab format (first example), but when a new line is created after an if statement, it'll only add 4 spaces? Normally. I would just reformat the whole file with a formatter and select those options, but that would make looking at changes when pushing to git nearly impossible, plus the other software engineer still uses the tab 8, spaces 4 system to edit.
Any help is appreciated!
Indentation is same in whole file,
you cant use two saperate indentation at once
simple solution will be: set your tabs to 4 spaces and use tabs 1 and 2 times whenever needed.
For reference: Indentation | VS Code Docs

Eclipse: use both tabs and spaces for indentation

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):

VSCode: keeping indents on empty lines

Is it possible to make VSCode keep indents on empty lines?
Could not find such a setting neither natively nor in "Beautify" extension.
Example of desired behavior:
UPDATE: eventually I've just switched to Prettier - and never had to think about code style again as it's just being formatted automatically for me.
Go to File > Preferences > Settings. On the right side, add the line:
,"editor.trimAutoWhitespace": false
It worked for me perfectly.
Bit of an old question, but I found that a combination of the settings:
"editor.trimAutoWhitespace": false,
"editor.renderWhitespace": "all"
...worked for me.
NOTE: (19/03/2021)
It appears that this issue, registered on GitHub, is still an open case.
As of: 2022-02-01
Here is the solution that worked for me even with VSCODE formatting(linting) on:
There are two native VSCODE settings that format your code automatically:
"editor.formatOnSave": true,
"editor.formatOnType": true,
These settings affect your text editor only if
"editor.defaultFormatter" is not null
Here are the problems
The "editor.trimAutoWhitespace" VSCODE setting solves the problem but only works on the "editor.formatOnType" autoformat, when you save the document this setting is ignored.
You may also want to trimAutoWhitespaces on all cases but the ones where you are leaving an indent on an empty row. (this was my case).
In my case, while coding, I test my code in the terminal chunck by chunck. The problem with, in my case, python is that the end of a for loops and a conditional is defined by indentation. In this case since the terminal run the code line by line, and not in chuncks, with the removal of the indentation, the terminal thinks that the for and if commands are finished before they actually are.
Here is the solution:
Never define an edit.defaultFormatter in your VSCODE settings define it per language.
How do you do that?
Change VSCODE "editor.defaultFormatter" to null as in:
"editor.defaultFormatter": null,
Change the language formatter to your prefered one. In my case:
python.formatting.provider": "black"
VSCODE gives you the possibility of choosing a formatting (linting) provider for any language. These providers' rules are way more detailed than the VSCode native rules. In VS code press CRTL+SHIFT+P and search for "preferences: Configure Language Specific Settings...". Then define your formatting provider for said language.
Every provider (in my case "black") provides the option of ignoring some sort of formatting rule. Set the ignore argument for this provider.
In my case I only ignore 2 rules and my setting is:
"python.formatting.blackArgs": [ "--ignore=E501,W293" ],
Rule E501 = Row with more than 80 character.
Rule W293 = Empty Row containing only WhiteSpaces.
Ignoring W293 allows the Auto Trim White Spaces to keep working for every kind of trailing White Spaces except for the case referred to in W293.
I had the same issue but after removing :
"editor.autoIndent": "none"
I was good to go.
Timestamp:
2021, using VS Code v1.56.2
Use Case:
You use editor.action.trimTrailingWhitespace. Later you wish to write new code in a function. You navigate to a blank line within the function, but discover this line isn't indented and is completely empty. In this scenario, you have four choices:
Hit Tab multiple times until your cursor is at the proper indentation.
Navigate up to a line with proper indentation, press End, then press Enter.
Click your mouse to the right of a properly indented line, then press Enter.
Press Ctrl + ] repeatedly to indent the empty line.[See Footnote 1]
This answer automates this workflow by inserting the indentation for you (when you navigate to an empty line surrounded by indented lines).
Background:
Spent 3 hours trying all of the solutions on this page (and many different extensions). Couldn't find anything else which worked.
Solution via Extension
implicit-indent Extension by jemc:
https://marketplace.visualstudio.com/items?itemName=jemc.vscode-implicit-indent
Automatically indents an empty line when navigated to (if its surrounding lines are indented).
Functionality
From experimenting, here's how implicit-indent seems to work:
Checks and matches either tab or space indentation automatically.
Determines spaces or tabs based on indentation of surrounding text, regardless of editor settings.[See Footnote 2]
Clicking on an empty line automatically indents to match surroundings.
If pressing the up ↑ or down ↓ arrow key navigates the caret (a.k.a. text cursor) to an empty line, implicit-indent will automatically indent the line and place the cursor to the right of the indentation (making it feel the same as if the line were already indented).
-> Before ↑ or ↓ is pressed, it doesn't matter what column the caret is on, this extension will trigger regardless.
 
Navigating to an empty line matches nested indentation.
Assume you have the following:
Where |n| represents a line
and c represents the caret / text cursor
and only line |2| is empty.
|1| indented line
|2| (empty line)
|3| c indented line
^ assume caret is on line |3|
(caret can be at any column)
Pressing the up ↑ arrow key results in the following:
|1| indented line
|2| c
|3| indented line
^ Line |2| (previously empty)
is automatically indented to
match nested indentation
of line |3|
and the caret is automatically moved
to the end of the inserted whitespace
(as if the line were already indented).
VS Code
As of 2021 May, the following GitHub issues are still unresolved:
https://github.com/microsoft/vscode/issues/49661
https://github.com/microsoft/vscode/issues/54210
https://github.com/OmniSharp/omnisharp-vscode/issues/1980
https://github.com/OmniSharp/omnisharp-vscode/issues/1680
Using implicit-indent is the only workaround I've discovered so far.
I'll amend this answer when automatic indentation is added to VS Code's native settings.
[Footnote 1]
As an alternative to this extension, you can use Tab or the following indent/unindent functionality built-in to VS Code to manually indent an empty line. Slightly out of scope, but it's a good hotkey to know about.
Default built-in hotkeys are:
Hotkey: CTRL + ]
Command: editor.action.indentLines
What it does:
Indent current line (if no selection)
or indent all selected or partially-selected lines.
Hotkey: CTRL + [
Command: editor.action.outdentLines
What it does:
"Outdent" (a.k.a "unindent" a.k.a dedent)
current line (if no selection)
or outdent all selected or partially-selected lines.
[Footnote 2]
Note: regardless of whether you use this extension or not, you can quickly replace your current document's indentation (to either leading tabs or leading spaces) by using the following VS Code commands:
editor.action.indentationToTabs
editor.action.indentationToSpaces
That is probably eslint (and/or beautify) doing that. Look at
"no-trailing-spaces": ["error", { "skipBlankLines": false }],
I have that in my eslintrc.json file and so I get errors on blank lines with spaces or tabs on them. Setting "skipBlankLines" to true might work for you.
Answer edited as for VSC version 1.56.2 and newer.
The command editor.action.insertLineAfter makes a new line and moves the cursor there preserving the indentation.
To bind that command to Enter key, go to your keyboard shortcuts (press ctrl + k ctrl + s) then press the page with the pivot arrow icon on the far right top.
add the following inside keybindings.json to look like so:
// Place your key bindings in this file to override the defaults
[
{
"key": "enter",
"command": "editor.action.insertLineAfter",
"when": "editorTextFocus && !editorReadonly"
},
]
It worked for my without re-opening of VSC
I was having this issue with writing Flutter code.
Only solution for me was to change my default formatter to Flutter.
UPDATE: I also needed to disable Dart: Enable SDK Formatter

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.