Skip to content

Auto Indent / Code Formatting / Beautify #4039

Closed

Description

This is an ongoing feedback issue from User Voice.

Activity

  1. added
    feature-request
    on Mar 11, 2016
  2. waderyan commented on Mar 11, 2016

    @waderyan
    Author

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

  3. waderyan commented on Mar 11, 2016

    @waderyan
    Author

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

  4. waderyan commented on Mar 11, 2016

    @waderyan
    Author

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

  5. waderyan commented on Mar 11, 2016

    @waderyan
    Author

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

  6. waderyan commented on Mar 11, 2016

    @waderyan
    Author

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

  7. waderyan commented on Mar 11, 2016

    @waderyan
    Author

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

  8. waderyan commented on Mar 11, 2016

    @waderyan
    Author

    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"

  9. jreadytalk commented on Mar 11, 2016

    @jreadytalk

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

  10. geomorillo commented on Mar 11, 2016

    @geomorillo

    Autoformat like netbeans does...

  11. waderyan commented on Mar 11, 2016

    @waderyan
    Author

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

  12. mrboring commented on Mar 12, 2016

    @mrboring

    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. 
    "@
    }
    
  13. stylemistake commented on Mar 14, 2016

    @stylemistake

    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! 😃

  14. JVimes commented on Mar 14, 2016

    @JVimes

    Ooo, pasting with correct indentation should be the default.

  15. cs04riva commented on Mar 15, 2016

    @cs04riva

    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;
    }
    
  16. 127 remaining items

  17. luchillo17 commented on Jun 11, 2018

    @luchillo17

    Sight...
    Lower right corner, if that kind of file doesn't have a parser associated you'll see something like "Plain Text", if it does it will state the mode like "Html" or "JavaScript" or "TypeScript"...

    Also anything you can do through interface can be done through the command palette, press Ctrl + Shift + P and type "Language", one of them should say "Change Language Mode".

    Then is up to you which one you want to select, you said you want Html right? just type html and select one of the options.

  18. bexoss commented on Jul 30, 2018

    @bexoss

    auto formatting jsx file is going crazy, How can I avoid this?
    12122

  19. sam0x17 commented on Jul 30, 2018

    @sam0x17

    sam0x17 (@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

    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.

  20. clocksmith commented on Aug 19, 2018

    @clocksmith

    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.

    if (x) {
      good();
    }
    

    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)

    const stream = getSomeSource()
        .map(...)
        .filter(...);
    

    I would even settle for this (2 spaces, same as my default indent)

    const stream = getSomeSource()
      .map(...)
      .filter(...);
    

    But this is what I get before running the format command.

    const stream = getSomeSource()
    .map(...)
    .filter(...);
    

    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:
    A. The cursor always knows where it should be after hitting enter.
    B. EditorConfig-like continuation_indent_size so that the above can be fine-tuned.

    This is what the config looks like in Intellij:

    screen shot 2018-08-19 at 4 27 46 pm

  21. removed their assignment
    on Sep 18, 2018
  22. zenoven commented on Oct 4, 2018

    @zenoven

    exactly the same issue with clocksmith

    spent too much time searching for a solution but none succeed

  23. stephengardner commented on Oct 19, 2018

    @stephengardner

    +1000 to what clocksmith said.
    That's EXACTLY what I came here hoping to find.

    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.

  24. sam0x17 commented on Oct 19, 2018

    @sam0x17

    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.

  25. drdebmath commented on Oct 30, 2018

    @drdebmath

    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.

  26. createdbyjurand commented on Nov 9, 2018

    @createdbyjurand

    Could you please add to Visual Studio Code some way to configure "Format Document" option.
    It would really help us with work. When we work in teams where everyone uses different editor, VSC cannot be configured as the team decided the code should look like. So I am forced not to use VSC because this is not configurable. This is deal breaker for me. Using VSC makes my Git commits have so many differences that this makes other team crazy.

  27. sam0x17 commented on Nov 9, 2018

    @sam0x17

    I second what Jurand (@createdbyjurand) says, this is a desperately needed feature. Eclipse has this, and Atom to a lesser extent.

  28. sanjayabc1234 commented on Jan 16, 2019

    @sanjayabc1234

    Hello,
    I was checking copy pasting of Python code in a markdown editor such as stackedit.io, the code looses its indentation. Whereas if I copy the same code from Sublime, the indentation is preserved on such markdown editor.

    Any idea how to resolve this issue?

    Thanks,

  29. mjbvz commented on May 1, 2019

    @mjbvz
    Contributor

    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

  30. locked and limited conversation to collaborators on Jun 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    editor-autoindentfeature-request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions