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

Unable to replace single quotes surrounding string with double quotes like I can in Vim #3657

Closed
pushkin- opened this issue Apr 5, 2019 · 3 comments

Comments

@pushkin-
Copy link

pushkin- commented Apr 5, 2019

I'm trying to replace strings surrounded by ' with ".

In Vim, I can do this:

%s/\'\([a-zA-Z-_]\+\)\'/"\1"/g

Which will change the input asd 'as-d_ad' asd to asd "as-d_ad" asd

In this extension, nothing happens. It can't find the match. I think this is related to the fact that some characters here aren't metacharacters even though they are in Vim and vice versa.

I tried something like this which did find the pattern, but it's replacing it with the literal "\1":

%s/'([\w-_]+)'/"\1"/g
  • Extension (VsCodeVim) version: 1.3.0
  • VSCode version: 1.32.1
  • OS: Windows 10
@rickpr
Copy link
Contributor

rickpr commented Apr 5, 2019

Maybe your use case is different - I like to use the vim-surround options though, it's enabled by default in VSCodeVim.

I place my cursor inside the string that I would like to replace the surrounding quotes and do cs"' and it does the replacement described above.

@myNameIsKeith
Copy link

@rickpr The 'cs' key sequence does nothing in VIM unless you have it mapped or have some other plugin that makes use of that particular sequence.

@pushkin-
According to the ROADMAP.md, "Currently we only support JavaScript Regex but not Vim's in-house Regex engine."

JavaScript uses the '$' character as a back reference rather than a backslash.

%s/'([\w-_]+)'/"$1"/g

Refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_parenthesized_substring_matches

@pushkin-
Copy link
Author

@anotherKeith Thanks that works

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

3 participants