Is it possible to format all of the code in Visual Studio Code to my specific prefrences.
I want the formatter to leave a space before any brackets and go onto a new line before and after any curly braces.
I do not want the formatter to format the code in any other way. I only want to format the code in these two ways.
This format should be applied automatically to any code I write after I hit save.
I have looked online and found the Prettier extension. Hovewer, this extension also formats the code in many other ways. I only want the code formatter to leave a space before any brackets and go onto a new line before and after any curly braces.
Related
I am usin vscode to work on my scss. Whenever I format my code with Beautify css/sass/scss/less v2.3.3 by michelemelluso, I get a linebreak before each comma in the fromatted code. What line do I have to write into the beautify.options of the extension to avoid that?
I want visual studio code to suggest an autocompletion for an entire line if I start typing the first few characters of any line already in the file, regardless of the content of the existing line. So if this is the content of my file:
this is a line with whitespace
this,is,a,comma,separated,list
And I type this on a new line, I would get a pop-up like any other autocomplete suggestion and I could fill in either of the lines above. How can I do this (and if I can't, is there another editor that has this ability)?
The extension Line Completion does what you want.
You have to configure for which files (language identifiers) it should perform these suggestions. (To prevent to much calculation on large files where you don't use it. See the README page.
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 am using prettier with VSCode, How can I configure it to format my code like this :
function test()
{
if()
{
MYCODE GOES HERE;
}
}
I want the { and } on new lines, and an empty line after { and before }.
Currently, it moves the curly brackets to same lines if condition or function name, and also remove the empty lines after/before { and }.
Prettier is considered an " opinionated " formatter, which means it doesn't let you choose things like that. If you want more control over the formatting, you can use a different formatter.
The built-in VS code formatter allows you to do what you're looking for, just search the settings for " function new line " and similar options.
There are of course many other formatting extensions available in the VS code marketplace as well. Whichever you choose, you will have to select it has your default formatter in your VS code settings.
As mentioned in this answer, VS Code's formatter itself works quite well, but if you want this to be part of workflow, then using ESLint might make things easier. There's a rule called brace-style.
You can then run eslint ./path/to/your/file --fix to format your code, or eslint . --fix to format code in the entire project directory.
Disclaimer: I use ESLint for code formatting most of the time and it works for me. I actually use it to find & fix problems too so it's like killing two birds with one stone, but note that ESLint is more about finding problems in the code and fixing them, so using ESLint just for code formatting might not be the best idea.
The DocBlockr package for sublime offers the feature "Inside a comment block, hit Alt+Q to wrap the lines to make them fit within your rulers." That's very handy when editing multiline file descriptions. Is there any good way to do that in Visual Studio Code? Manually reformating line breaks and initial asterisks within a JSDoc comment is a pain in the neck.