VSCodeVim / VSCodeVim/Vim

`:s[ubstitute]` not handling backslashes correctly

Open
#6,601 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/commandline kind/bug
Dominant language
TypeScript
Stars
15.2k
Forks
1.5k
Avg merge
3d 18h
Merged PRs (30d)
6

Description

Describe the bug
A clear and concise description of what the bug is.

I have a line of text like C:\\Program Files\\Microsoft and I want to replace all double backslash (\\) to single backslash (\), so I tried below command line substitution:

:s/\\\\/\\/g
or
:s/\\\\/\/g
or
:s/(\\)\\/$1/g

The first command did nothing, and so I tried the second one, which replaced double backslash (\\) to single slash (/). Only the third one worked as what I expected.

Both 1st and 3rd command worked well in gVim 8.2.12 (though need to replace $1 to \1).

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
If remapping-related, please attach log output: https://github.com/VSCodeVim/Vim#debugging-remappings.

Environment (please complete the following information):

  • Extension (VsCodeVim) version:1.20.2
  • VSCode version:1.56.0
  • OS: Windows 10

Additional context
Add any other context about the problem here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the :s[ubstitute] command entry point and reproduce the three substitutions described in the issue using VSCodeVim on Windows. Trace how backslashes and replacement references are parsed, then verify that replacing double backslashes with single backslashes behaves as expected without changing them to slashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, vim
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.