vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Auto Indent / Code Formatting / Beautify

Open waderyan opened this issue 10 years ago • 146 comments

This is an ongoing feedback issue from User Voice.

waderyan avatar Mar 11 '16 20:03 waderyan

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."

waderyan avatar Mar 11 '16 20:03 waderyan

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."

waderyan avatar Mar 11 '16 20:03 waderyan

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?"

waderyan avatar Mar 11 '16 20:03 waderyan

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. "

waderyan avatar Mar 11 '16 20:03 waderyan

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."

waderyan avatar Mar 11 '16 20:03 waderyan

From User Voice - HTML / CSHTML editing capabilities "Just look at VS2015's capabilities during editing of an HTML or CSHTML file - replicate that."

waderyan avatar Mar 11 '16 20:03 waderyan

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"

waderyan avatar Mar 11 '16 20:03 waderyan

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

jreadytalk avatar Mar 11 '16 21:03 jreadytalk

Autoformat like netbeans does...

geomorillo avatar Mar 11 '16 22:03 geomorillo

@geomorillo can you be more specific? What exactly does Netbeans do that is missing?

waderyan avatar Mar 11 '16 22:03 waderyan

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. 
"@
}

mrboring avatar Mar 12 '16 08:03 mrboring

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:

stylemistake avatar Mar 14 '16 09:03 stylemistake

Ooo, pasting with correct indentation should be the default.

JVimes avatar Mar 14 '16 15:03 JVimes

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;
}

cs04riva avatar Mar 15 '16 13:03 cs04riva

Format code does not work on .scss files.

wembernard avatar Mar 16 '16 09:03 wembernard

This is a standard CSS file.

cs04riva avatar Mar 16 '16 14:03 cs04riva

+1

pdefreitas avatar Mar 22 '16 11:03 pdefreitas

@cs04riva: Sorry for misleading. I was just adding another feature I'd love.

wembernard avatar Mar 22 '16 15:03 wembernard

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.

ganeshkbhat avatar Mar 23 '16 12:03 ganeshkbhat

I would really love to see an option to format on save

alexgorbatchev avatar Apr 01 '16 16:04 alexgorbatchev