code icon indicating copy to clipboard operation
code copied to clipboard

Automatically remove trailing spaces after pressing Enter

Open dillonfagan opened this issue 6 years ago • 6 comments

Feature request: Like Visual Studio, it would be awesome if Code could satisfy my OCD by clearing spacing (and tabs) from empty lines, i.e. lines with no text in them. The company I work for has made it part of their coding standards that blank lines should be completely blank, including any excess spacing.

dillonfagan avatar Nov 10 '18 01:11 dillonfagan

Enable the plugin Strip trailing whitespace from the preferences dialog. It does exactly that.

image

arshubham avatar Nov 10 '18 05:11 arshubham

Ah now I feel slightly foolish... except am I right that this only works when manually saving? I'd like for trailing spaces to be stripped in real-time if that's possible.

dillonfagan avatar Nov 10 '18 13:11 dillonfagan

yeah you are right. Title can me made a little clearer. Anyway someone needs to just call it on enter key press event instead of save event and submit a new plugin. Is this how vscode handles it? Does it remove the whitespaces from whole file or just the current line?

arshubham avatar Nov 10 '18 13:11 arshubham

I think as you type, Visual Studio (not sure about VS Code) removes trailing spaces from the current line after hitting enter/return.

dillonfagan avatar Nov 10 '18 13:11 dillonfagan

If stripping is enabled for automatic save then it should not be applied to the line being typed.

jeremypw avatar Mar 07 '21 17:03 jeremypw

This could be annoying as I often temporarily move away from the current line which might contain space (tabs) which I do not want removed at that point as I want to paste something afterwards. You can force stripping just by pressing <Ctrl>S if you want. You should always check for trailing space before committing anyway using the linter io.elementary.vala-lint

jeremypw avatar Jul 07 '23 12:07 jeremypw