Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't delete blank lines when trimming whitespace #9460

Open
nick-knight opened this issue Jan 24, 2025 · 0 comments
Open

Don't delete blank lines when trimming whitespace #9460

nick-knight opened this issue Jan 24, 2025 · 0 comments

Comments

@nick-knight
Copy link

nick-knight commented Jan 24, 2025

First of all, from a Vim user who's recently been coerced to use VSCode: thanks for your hard work on this plugin.

Is your feature request related to a problem? Please describe.

Well, it's a problem for me. From searching the Issues, it doesn't seem to have been reported before.

Describe the solution you'd like

In Vim, I'm accustomed to trimming trailing whitespace via something like the following:

:%s/\s\+$//g

In VSCodeVim, this gives E486: Pattern not found: \s\+(?:$(?<!\r)). By trial and error, I was able to get close to my desired behavior by omitting the backslash preceding the plus sign,

:%s/\s+$//g

After this modification, VSCodeVim removes trailing whitespace as desired. Unfortunately, there are two drawbacks.

First, this command also removes blank lines, i.e., lines containing zero or more whitespace characters followed by a newline. This is highly undesirable behavior: blank lines have special meaning in certain programming languages, and they are also a popular technique to improve readability. I much prefer the Vim behavior, where the whitespace is removed but the newline is preserved.

Second, this command behaves quite differently in Vim, where the plus sign would be interpreted literally. (Although I'm sure this can be customized.)

Describe alternatives you've considered

Under settings, VSCode has a "Trim trailing whitespace upon saving file". This seems to do the right thing, but unfortunately affects a file globally. Even if removing the trailing whitespace is the morally correct thing to do, this can cause practical issues when collaborating on projects or working with legacy codebases.

Additional context

My background is Linux-command-line-based development using Vim as my editor. I'm new to VSCode-based development on MacOS. It is possible I've overlooked some configuration setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant