VS Code currently removes all trailing whitespace including on whitespace only lines.
Consider the following JavaScript/Typescript snippet:
export default class Example {
constructor() {
console.log("called constructor");
}
doSomething() {
console.log("I did something.");
}
}
When I come back to this file, I expect to be able to move the cursor between the two methods and add a new one in between without having to hit the tab key, but after running the VS Code formatter, the whitespace on that line (ln. 5) is removed.
Atom supports this under an "Ignore Whitespace Only Lines" setting.
Additionally, there's a VS Code extension which adds this functionality.
Trailing Whitespace VS Code Plugin
It'd be really great if it were configurable and/or auto-detected on a per-file basis by the editor, and would really help my workflow.
Thanks so much,
Andrew
Is there any solution to this isuue with or without an extension? It drives me crazy for months now. I would like the cursor to be placed respecting indentation in empty lines after formatting. Thanks!
+1 for this request. I know it might seem like a small thing, but having my cursor keep in line (at least having an option to ignore whitespace) would really improve my workflow and quality of experience.
@alexandrudima Could you shed some light on this issue?
Is this a technically difficult task? Would you guys be open to this functionality? Would you be able to provide some info on what would be required?
Thanks for the work you're doing on VS Code. It's awesome.
Andrew
@andrewrothman
I don't think it should be a difficult task.
It's just adding a config that when the trim code encounters a line that ends in whitespace, it checks it doesn't match the regex ^\s+$
@andrewrothman @Gkupce I don't know when this appeared, since I found it by accident when looking for something else, but if you look for "Editor: Trim Auto Whitespace" in the preferences and un-select it, it does appear to have the desired functionality.
I believe this thread can be closed.
That option only prevents automatically inserted whitespace being 'immediately' removed. It doesn't help when you're formatting a file.
@tarsupin Thanks for the tip. Looks like there's still some unexpected behavior with formatting as per @HoldYourWaffle's comment. Also, I'm not sure if that setting takes this into account or not, but I'd be interested in removing whitespace at the end of non-empty lines, but preserving whitespace-only lines. I never add extra tabs or spaces after a line of code, but I do use whitespace-only lines to navigate easier while I'm writing code.
Also, I'm not sure if that setting takes this into account or not, but I'd be interested in removing whitespace at the end of non-empty lines, but preserving whitespace-only lines. I never add extra tabs or spaces after a line of code, but I do use whitespace-only lines to navigate easier while I'm writing code.
This is exactly what I'd love to have. As far as I know there sadly isn't a built-in solution for this right now.
I'd be interested in implementing this. Does anyone know if there is a process to have the idea reviewed/modified/approved by the VS Code team before writing code? Or if someone could provide some guidance in the code architecture? I think this would require changes to the settings system (replacing that setting with an enum dropdown versus a checkbox) and whatever subsystem takes the current setting into account. Also, can anyone spot any potential issues with other formatters / extensions that might impact this?
Is there any movement on this? Really driving me crazy.
Now we have "files.trimTrailingWhitespace": true config for it.
@andrewrothman How did you solve?
I wish I knew -- I wrestled with this forever, and it works now, but I
can't remember what I changed. I can send my entire config if it'll help?
W. Sean Harrison
CTO, Principal
Hagimo LLC
p: 615.838.9289
e: sean.[email protected]
The contents of this email message and any attachments are intended solely
for the addressee(s) and may contain confidential and/or privileged
information and may be legally protected from disclosure. If you are not
the intended recipient of this message or their agent, or if this message
has been addressed to you in error, please immediately alert the sender by
reply email and then delete this message and any attachments. If you are
not the intended recipient, you are hereby notified that any use,
dissemination, copying, or storage of this message or its attachments is
strictly prohibited.
On Wed, Aug 19, 2020 at 9:35 PM luke-uppx notifications@github.com wrote:
@andrewrothman https://github.com/andrewrothman How did you solve?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/vscode/issues/49661#issuecomment-676862385,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ANFKCIDDLUIKN4KZEGME5ILSBSDVVANCNFSM4E7LJD2Q
.
I can send my entire config if it'll help?
@Scatterblak please, if you want.
Most helpful comment
Is there any solution to this isuue with or without an extension? It drives me crazy for months now. I would like the cursor to be placed respecting indentation in empty lines after formatting. Thanks!