Auto Indent / Code Formatting / Beautify
From User Voice - Maintain indentation level on copy and paste "When you cut a block of code and paste it somewhere with a different indentation level (i.e. inside nested ifs) it'd be nice to get it properly indented, automatically on paste."
From User Voice - Auto indenting line based on language's standard "In PyCharm, when you type ":" and press Enter then the next line is automatically indented to the appropriate level according to the chosen language's standard."
From User Voice - Tab size per language "One specific thing that I've came across though: I've set my tab size to 2 in my user settings file. That tab size is honored when I format a .ts or .js file. It is NOT honored when I auto format a .cs file - then it seems to go on a 4 space indent. Is this a separate setting?"
From User Voice - CSS / Less indenting "The only thing that's missing for me is the out of the box LESS indent functionality (all other file types I work with work just fine). I had to install a plugin that auto formats CSS but it's not exactly the same. It's also missing some features like preserving spaces/line breaks and so on... something that should be configurable if you're adding this support. "
From User Voice - Format issues with C# "This needs to be added. I want to write my C# code with the K&R style, but every time I try to format it it screws everything up."
From User Voice - HTML / CSHTML editing capabilities "Just look at VS2015's capabilities during editing of an HTML or CSHTML file - replicate that."
From User Voice - Auto formatting "It should pick up the type of language based on the choice you made at the bottom right of the screen. If I open a .log file for instance that has xml in it, I would like it to autoformat to the xml setting I changed it too. using the editor.action.format ONLY works based on the file name not what I have told it the contents are. Definitely should appear on the context menu"
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): Heredoc text is not folded as the end tag must have no white space before it. Often heredoc text has no leading whitespace on any line.
Here is the code I used for testing:
function FunctionName {
$a = @"
This is some sample text to
demonstrate a code folding issue
withing VS Code.
"@
}
Sublime Text 3 has the feature to paste text with automatic indentation (Ctrl+Shift+V), which basically adds or removes levels and adjusts the first line to match the current block indentation.
UPD:
This behavior can be default for Ctrl+V (like in IntelliJ IDEA, afaik), and have Ctrl+Shift+V for HTML previews as it is right now.
UPD 2:
There is an extension that adds an extension.pasteAndFormat command, which can be used in keybindings.json (combination of editor.action.clipboardPasteAction and editor.action.format).
I thought why not allowing users to define keybindings with multiple commands using the array syntax, like this?
...
{
"key": "ctrl+shift+v",
"command": [
"editor.action.clipboardPasteAction",
"editor.action.format"
]
}
...
This would solve the problem and add a possibility to create mini-macros, sort of! :smiley:
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:
body{background-color:#FFF;}#test{position:absolute;}
Would turn into:
body{
background-color:#FFF;
}
#test{
position:absolute;
}
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. The indenting leaves some tabs/spaces in the left sometimes. Specially in cases of HTML. Cases like a blank line/row is also left as is and is not removed. You can have visual studio code settings for this whether to remove blank lines/rows May be this is on purpose I guess. More, what is missing is in-file/active-file code minification/uglifying/removing blankspaces etc for all supported languages. A nice valueadd to have when having indenting/formating.
I would really love to see an option to format on save