Skip to content

Improve indentation of lines #28658

Closed
Closed

Description

@rebornix

Auto indent support for type, move lines and copy/paste

Type

defend

Move Lines

movelines

Copy Paste

copypaste

Activity

  1. borekb commented on Jun 15, 2017

    @borekb

    Is this universal across languages? Does that mean that VSCode will finally be able to re-indent? Related: #19847

    Thanks for your work on this.

  2. rebornix commented on Jun 15, 2017

    @rebornix
    ContributorAuthor

    Borek Bernard (@borekb) first of all, languages need to define indentation rules, otherwise we don't know how to adjust the indentation. secondly embedded language may not work properly as the language service for embedded languages are not avail if you don't open the file marked as that particular language.

  3. vvs commented on Jun 18, 2017

    @vvs

    Please consider adding a keybinding to "auto-indent current line" behavior, similar to what other editors do, like in Atom, with the use of editor:auto-indent:
    '.platform-win32 atom-text-editor': 'ctrl-i': 'editor:auto-indent'

    , or like in Sublime:
    { "keys": ["f12"], "command": "reindent", "args": {"single_line": true} }

    As far as I can tell, currently there is no way to auto-indent the current line.

  4. rebornix commented on Jun 19, 2017

    @rebornix
    ContributorAuthor

    Vladimir Sizikov (@vvs)

    auto-indent the current line

    are you referring to run a command to adjust the indent of current line? If so add an optional argument to reindent all lines can be a solution.

  5. vvs commented on Jun 20, 2017

    @vvs

    Peng Lyu (@rebornix)

    Yes, please. Essentially, there should be a way to do 3 things via keyboard shortcuts:

    • Indent the whole file (as far as I understand reindentAllLines does that currently)
    • Indent the selection
    • Indent the current line (when there is no selection)
  6. borekb commented on Jul 11, 2017

    @borekb

    Just tried the behavior in 1.14 in a JSON file, it seems that the internal engine for indentation is becoming great but I'm still missing the command(s) to re-indent just the current line or the selection as vss said. Ctrl+I is actually the very command I have it mapped to :)

    Actually, thinking about it some more, I very rarely re-indent the whole file and almost always care only about the current line or small chunk of code. So if it was up to me, I'd propose a change of behavior of editor.action.reindentlines (should be editor.action.reindentLines, see the upper-case L) to this:

    • If there's no selection, re-indent the current line.
    • If there's a selection, re-indent all the lines it is touching.

    Full file re-indentation would be done by simply Ctrl+A and kbd(editor.action.reindentLines).

    Thanks for your continuing work on this!

  7. added
    feature-request
    on Aug 11, 2017
  8. antcodd commented on Oct 25, 2017

    @antcodd

    The current behaviour of reindent lines indenting all lines is very confusing. To me the main use for that command would be to reindent blocks after typing in an order not handled by the above improvements. The most common case is wrapping existing code in if { }, such as after pasting. Ideally the language indentation rules would handle this case (I am using C) but the ability to do a manual fixup of crazy indenting without affecting the rest of the file is useful and something I use frequently in vim. In this case I was actually trying to work around #6392.

    PR #35594 looks like it changes Reindent Lines to reindent the selection when there is a selection. I think I prefer Borek Bernard (@borekb)'s suggestion of reindenting the current line with no selection. The current reindent all feature could be kept as a separate command in which case it should probably be called Reindent Document for consistency with Format Document and to actually be clearly named. I'm not sure if it is also feasible to have Format work over a range?

    I also notice that reindent lines also doesn't respect editor.trimAutoWhitespace, re-adding space in blank lines all through the file. Is there an issue for that?

    This is even more dangerous now that the default behaviour is to not show whitespace changes in diff or the git changes gutter.

  9. borekb commented on Oct 25, 2017

    @borekb

    I also notice that reindent lines also doesn't respect editor.trimAutoWhitespace, re-adding space in blank lines all through the file. Is there an issue for that?

    I don't think there is and you're right that it's one of the small but annoying issues with the current implementation. In my own setup, I have .editorconfig that influences how empty lines are treated, ideally it would be taken into consideration but I acknowledge that .editorconfig is supported via extension, not core.

  10. rebornix commented on Sep 18, 2018

    @rebornix
    ContributorAuthor

    This issue was created for tracking the todos we were working on auto indentation. Issues mentioned above are being tracked in separate issues so we close this one for better issue tracking.

  11. locked and limited conversation to collaborators on Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

editor-autoindentfeature-request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions