-
Notifications
You must be signed in to change notification settings - Fork 29.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto Indent / Code Formatting / Beautify #4039
Comments
From User Voice - Maintain indentation level on copy and paste |
From User Voice - Auto indenting line based on language's standard |
From User Voice - Tab size per language |
From User Voice - CSS / Less indenting |
From User Voice - Format issues with C# |
From User Voice - HTML / CSHTML editing capabilities |
From User Voice - Auto formatting |
Currently there's no auto-indentation for CoffeeScript (e.g. function, condition, and loop bodies), and in some situations tab key produces 4 spaces in a 2 space file (default indentation settings). |
Autoformat like netbeans does... |
@geomorillo can you be more specific? What exactly does Netbeans do that is missing? |
Powershell (I suspect this may be the same for other languages): Here is the code I used for testing:
|
Sublime Text 3 has the feature to paste text with automatic indentation ( UPD: UPD 2: I thought why not allowing users to define keybindings with multiple commands using the array syntax, like this?
This would solve the problem and add a possibility to create mini-macros, sort of! 😃 |
Ooo, pasting with correct indentation should be the default. |
Formatting CSS doesn't seem to properly work anymore. You use to be able to paste in a block of css in one line, hit the shift + alt +f and it would correctly format the code. This no longer works. For example: Would turn into:
|
Format code does not work on .scss files. |
This is a standard CSS file. |
+1 |
@cs04riva: Sorry for misleading. I was just adding another feature I'd love. |
The current one is quite good. |
I would really love to see an option to format on save |
Using polymer which is a mix of html and javascript, shift + option + f doesn't work on it. You can use this as a test base for formating https://github.com/PolymerElements/polymer-starter-kit |
Just copy these guys and you'll be good to go: Ok, that might be too much. Can we start with "Refactor > Change Signature" and "Extract Method from Selection"? Live code analysis is also a must, or else VSCode will keep feeling like a glorified text editor - which's not really what a serious production code IDE is supposed to be. |
@MaDDoXbr but it is a text editor, not an IDE. |
I know, yet it could be a full-featured IDE if Microsoft wanted it to. |
No point in arguing text editor vs IDE (VSCode's selling points include features of both). Thin and popular features go into the base product, heavy or niche features into extensions. Correct indentation on paste and formatting support for more languages are obvious candidates for base product. |
The "paste and format" thing is only partly a solution for me. I would like to have the indention adjusted without any other modification of the pasted content - like it's in Sublime. The thing is, I sometimes accidentally introduce "wrong coding style" into a file in a repo which uses different coding style than what VSCode is configured to use. For example, I paste-and-format a piece of JS and VSCode changes the Also I noticed that often the even indention is not correct, for example the first line is not enough indented. Again, I do compare this to Sublime Text 3 because I'm in the process of switching from it to VSCode because I like several aspects more, but there are still issues like this which are very annoying. |
I agree with @CherryDT . Sorry, found the options: |
Two things I want to report on.
|
@halukkaramete I had the same problem for JavaScript files and got around it by changing the language mode to anything else (in this case, Batch file, because it was first on the list) before saving and then switching back after saving. I eventually got so annoyed by this that I disabled all extensions one by one and finally figured out that "vscode-json" was my culprit. I haven't had the issue since uninstalling it. |
I'm also struggling with this autoformatting issue. Whenever I paste a piece of code in my SASS files the new extra line is added. It makes such a mess in my code. Is there a way to prevent such a behaviour? |
<3 how developers need there brackets at the right spot to feel sane :) |
This stil doesn't fixed? #43859 How to autoindent Stylus? Super frustrating... |
Would be great if autoindent worked the same as in atom |
@rrd108 how were you even able to format a smarty template? I've just tried to format .tpl file using Alt+Opt+F, but it keeps saying "There is no document formatter for 'smarty'-files installed.". I'd be glad to apply ol'good-HTML formatting rules to this file (it doesn't have any smarty tags at this moment), but I don't see a way to do it… |
related to this #48341 |
I have spend at least 2.5 hours to fix this auto formatting on save issue and I had no success. This is really frustrating. the is no settings to stop this. |
Step 1. open op atom ;) |
But seriously, there should be some language-nonspecific way of converting say a 4-space indented file to a 2-space indented file. |
@mityukov Have you tried changing the language mode for the file to HTML before formatting? i've had success formatting files after changing the language mode to any, didn't matter the file extension. |
@sam0x17 There are plugins for such purpose, i'm not sure this is the best example but here's one: https://marketplace.visualstudio.com/items?itemName=Compulim.indent4to2 Also using auto-formatters like prettier should do the trick assuming you configure it correctly, though prettier might not be language agnostic. |
Nope. I've had such idea, but I couldn't find how :/ |
Sight... Also anything you can do through interface can be done through the command palette, press Then is up to you which one you want to select, you said you want |
My point is you shouldn't have to worry about finding a plugin for something basic like this. Atom does this out of the box without any plugins, and automatically can do it for any language that has a syntax highlighting plugin. Prettier/eslint/rubocop/whatever might not respect my user-configured tab/spaces preference (2 spaces always in my case) so you're taking something that should be a basic editor feature and leaving it up to the third party ecosystem which is going to do a terrible, inconsistent job with it because there are no editor-level conventions that let a language specify how the editor should do auto-indenting for that language. Right now my workflow is literally use vscode for most things, copy paste to and from atom whenever I need to mess with indents, because the vscode tools for that are that bad. |
I have default settings with 2 spaces for indent. I want the the cursor to figure out where it should be when I hit enter, as I am typing it, like every other IDE (Intellij, Xcode, Android Studio, Eclipse, etc) Stuff like this works fine.
Problems arise when I hit ENTER at the end of a statement on a multiline that ends in a diff column than it started, or hitting ENTER mid statement to break a longer line. For example: I would like this to happen as I type and press ENTER (4 spaces, double my default indent)
I would even settle for this (2 spaces, same as my default indent)
But this is what I get before running the format command.
I have spent hours with vscode settings and extensions but cannot get this simple behavior. The "formatOnType" option is close, but doesn't seem to work for ENTER key, and there are still no options for line-continuation, chained methods, etc. Ideally: This is what the config looks like in Intellij: |
exactly the same issue with @clocksmith spent too much time searching for a solution but none succeed |
+1000 to what @clocksmith said. It's actually not possible? Someone save us. I want to search for a plugin but seems like there have been many fruitless efforts and I've spent long enough configuring this to match the ease of use that WebStorm offered. |
agree, what @clocksmith said, with the addition that "auto format" should be an editor-level option that works for any language plugin like it does in Atom. |
Another thing I would like to point at is, when I am in a .php file, say it contains HTML. I can format the HTML by choosing the Language Mode to HTML. But it is better to have an option to directly format the php file without choosing to change the Language Mode option to HTML. It should be able to format the HTML in the php file. |
Could you please add to Visual Studio Code some way to configure "Format Document" option. |
I second what @createdbyjurand says, this is a desperately needed feature. Eclipse has this, and Atom to a lesser extent. |
Hello, Any idea how to resolve this issue? Thanks, |
Closing this aggregate issue as it is out of date and it is unclear what it is tracking If you are running into an issue with formatting or indentation, or would like to suggest a feature related to formatting or indentation, please open a new issue |
This is an ongoing feedback issue from User Voice.
The text was updated successfully, but these errors were encountered: