You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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).
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.
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.
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.
Activity
borekb commentedon Jun 15, 2017
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.
rebornix commentedon Jun 15, 2017
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.
vvs commentedon Jun 18, 2017
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.
rebornix commentedon Jun 19, 2017
Vladimir Sizikov (@vvs)
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.
vvs commentedon Jun 20, 2017
Peng Lyu (@rebornix)
Yes, please. Essentially, there should be a way to do 3 things via keyboard shortcuts:
borekb commentedon Jul 11, 2017
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 beeditor.action.reindentLines, see the upper-case L) to this:Full file re-indentation would be done by simply Ctrl+A and
kbd(editor.action.reindentLines).Thanks for your continuing work on this!
antcodd commentedon Oct 25, 2017
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.
borekb commentedon Oct 25, 2017
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
.editorconfigthat influences how empty lines are treated, ideally it would be taken into consideration but I acknowledge that.editorconfigis supported via extension, not core.rebornix commentedon Sep 18, 2018
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.