This is the formatting I want to achieve:
function x() {
$elementOfSomething
.find(".class")
.remove();
}
This is the formatting VSCode does by default:
function x() {
$elementOfSomething
.find(".class")
.remove();
}
The default indentation is 4 spaces. In the second sample, the third and fourth lines are indented by 4 spaces in relation to the previous line. In the first sample, they are indented by 8 spaces. So I want to the default indentation to be 4 spaces but the continuation indentation to be 8 spaces. In NetBeans, there is the setting "continuation indentation" for this. Is there a way to achive such indenation behaviour in VSCode (for JS and Java)?
In VS Code this setting is called "wrapping indent", and this setting is located within the Text Editor category of settings.
Sounds like you want to set your wrapping indent to the "deepIndent" option, which will relatively indent the wrapped line to the width of two tabs. For example, if your tab size setting is 4 spaces, a deepIndent will be 8 spaces.
Related
I want to remove the indentation lines that are marked in red as they serve no purpose. I want to make the indentation of 1 tab = 4 spaces, but VSCode automatically made it as 1 tab = 2 spaces. How can I fix this?
I want to remove the indentation lines that are marked in red as they serve no purpose.
File->Preference->Settings and search for "renderIndentGuides".
uncheck Editor: Render Indent Guides
I want to make the indentation of 1 tab = 4 spaces, but VSCode automatically made it as 1 tab = 2 spaces.
Gotto
File->Prefrences->setting -> Detect Indentation -> Click editor:TabSize
Here you can update to 4
How can we configure our VSCode to format C code as per our custom coding standard?
Formatting rules like -
Initial indentation is 4 spaces, next indentation is a tab, and one
more level of indentation is tab+4 spaces, another level is 2 tabs
and goes on.
And the opening braces to be on the same line as the if or for
statement?
How the indentation of the statement in the next line should be. Whether the statement inside if
statement should be indented or just be in the same column alignment as the if statement.
And so many other coding style formats.
When I was using Eclipse, I was able to create my custom profile and make all the necessary changes inside it like that -
I have file using an indentation level of 4 columns, and assuming that a tabulation character corresponds to 8 spaces, like this (I use . to represent a space, and <------> for a tabulation character):
class Foo {
....void bar() {
<------>if (boz) {
<------>....return x;
<------>}
....}
}
This is common for certain coding styles like Oracle coding conventions for Java:
Four spaces should be used as the unit of indentation. The exact construction of the indentation (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4).
I'm having trouble rendering this properly with VSCode:
If I set editor.tabSize to 4, then it renders badly as
class Foo {
....void bar() {
<-->if (boz) {
<-->....return x;
<-->}
....}
}
If I set editor.tabSize to 8, then the text is rendered properly, but the indentation guides are incorrect (a guide is missing for the void bar() indentation level):
More importantly, automatic indentation (pressing the "tab" key, or on-the-fly indentation when pressing "return" after a { character) now indents with 8 columns, making the editor barely usable.
An obvious workaround is to use only spaces for indenting, but this is not applicable when opening a pre-existing file.
Is there a way to configure the indentation guides to be displayed every 4 columns, while still rendering tabs every 8 columns?
In the editorconfig cross-editor configuration file specification, this corresponds to the tab_width and indent_size properties, that I would like to be able to change independently.
I'm a former Emacs-user, and this would correspond to tab-width and c-basic-offset for example.
The issue mentioned in the comments in 2020, microsoft/vscode issue 10339, has finally been closed in Nov. 2022(!)
PR 155450 enables having separate values for indentation and the display width of tab characters, which is a common requirement of some older projects and/or coding styles.
In addition to adding support for an editor.indentSize property, the indentation options on the status bar have been updated to allow independently configuring editor.indentSize and editor.tabSize.
So:
editor.indentSize: The number of spaces used for indentation or 'tabSize' to use the value from editor.tabSize.
This setting is overridden based on the file contents when editor.detectIndentation is on.
This should be available soon in VSCode Insiders and released with VSCode 1.74 (Nov. 2022).
Unfortunately, as of now there is no setting or extension that is based only on (spaces/tabs-at-the-current-tab-size).
When writing a source file in VS Code that is styled with spaces of a specific width (maybe determined by the .editorconfig file), how can I force VS Code to treat the spaces like tabs without reformatting the file?
For example, the indent width may be 4 spaces, so rather than displaying 4 spaces in my editor, I'd rather see one tab space character with a width of 4 spaces.
The selection aspect of space-tabulated code is supported with VSCode 1.52 (Nov. 2020) and:
Sticky Tab Stops when indenting with Spaces
If you prefer to indent your code with spaces, there is a new setting called editor.stickyTabStops, which makes VS Code treat cursor movements in leading spaces similar to tabs.
Appearance
You said vscode is:
displaying 4 spaces in my editor
I assume that means you're getting those little Interpunct dot characters coming up like this ยทยทยทยท
If you want those to go away, so they appear more consistent with tabs, go into VScode settings (JSON) and enter the following:
"editor.renderWhitespace": "selection"
Assuming everything else is default, both tabs and spaces should be rendered as regular whitespace. But that alone it doesn't really help, because it doesn't allow you to distinguish nested structures i.e. you can't tell how many levels of indentation you're at.
To fix that, there's 2 things.
(minimum) Set indent guides explicitly in your user settings, this will render vertical lines at each indentation level, no matter if the file is using tabs or spaces:
"editor.renderIndentGuides": true
(optional extra) If you want to take it further, there are a few extensions you can try, but the one i recommend is indent-rainbow. There are lots of options for it, but i have mine config'd so after a certain level of indentation it becomes more obnoxious, because i treat it as a code smell i.e. i like to minimize how much i nest if possible.
The end result of doing all this is that tabs and spaces are rendered exactly the same way, and you can't tell the difference unless you have part of your code highlighted:
Behavior
To make the behavior of indentation more consistent, the following should be in your settings if it's not already applied by default:
"editor.detectIndentation": true,
"editor.insertSpaces": true,
"editor.useTabStops": true
As for this:
source file in VS Code that is styled with spaces of a specific width (maybe determined by the .editorconfig file)
I don't think this is possible, or at least not natively. You may be able to find/write an extension that can do detection based on tabsize since there is in fact a property called:
"editor.tabSize": 4,
Not sure if this will help, but you can do selective setting overrides based on filetype, for example:
"[yaml]": {
"editor.insertSpaces": true,
"editor.tabSize": 2,
"editor.autoIndent": "advanced"
}
By this I mean if some file was written with 4 spaces, can you simply highlight it all and click on something to turn it into 2 spaces. I'm not sure if in practice (parsing) this would make sense/could lead to broken code.
I currently have my editor.tabSize set to 2, and sometimes I open files written with 4 spaces and I want to be able to turn them into 2 spaces. I have at least figured out to turn off the auto-detect so that when I highlight sections of the code and hit shift-tab, then tab again it will turn the selected code from 4 spaces into 2 spaces.
Is there a feature like this or does it make sense that this wouldn't exist?
To change the current document from using 4 spaces to 2 spaces:
Click on Spaces: 4 in the status bar or run the Indent using Spaces command
Select 2 for the new tab size
Run for Format Document command to apply the new indentation to the entire document