Don't delete blank lines when trimming whitespace
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 15.2k
- Forks
- 1.5k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 6
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing VSCodeVim's substitute command handling and the whitespace-matching behavior described in the issue. Reproduce both substitution forms with whitespace-only lines, then verify that trailing whitespace is removed while blank-line newlines are preserved and Vim's plus-sign behavior remains distinct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vscode
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100