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

Capturing group in search/replace #991

Closed
erigul opened this issue Oct 26, 2016 · 7 comments · Fixed by #1725
Closed

Capturing group in search/replace #991

erigul opened this issue Oct 26, 2016 · 7 comments · Fixed by #1725

Comments

@erigul
Copy link

erigul commented Oct 26, 2016

Please thumbs-up 👍 this issue if it personally affects you! You can do this by clicking on the emoji-face on the top right of this post. Issues with more thumbs-up will be prioritized.


What did you do?

In a document containing the string
some test text
run the command
:%s/te\(.\)t/\1/g

Put the exact keys you pressed.
: to open the vim command prompt, type in%s/te\(.\)t/\1/g and hit the Enter key.

What did you expect to happen?

some test text to be replaced with some s x

What happened instead?

Nothing

Technical details:

  • VSCode Version: 1.6.1
  • VsCodeVim Version: 0.4.0
  • OS: Windows 7
@johnfn
Copy link
Member

johnfn commented Oct 27, 2016

My guess is this is some consequence of the regex engine we're using, which is Javascript's, not Vim's.

@rebornix
Copy link
Member

@johnfn that explains difficult-hard :)

@DrakeXiang
Copy link

vscode's built in search support group capturing, can we use that?

@johnfn
Copy link
Member

johnfn commented Jan 24, 2017

Unfortunately, I doubt it, because it's highly unlikely that VSCode's capturing works in the same way as Vim's.

@lucastheisen
Copy link

lucastheisen commented Apr 9, 2017

You can use vscode's built-in search support for group capturing... You just need to use JS syntax instead. From the example in the original question, just use:

:%s/te(.)t/$1/g
:%s/te\(.\)t/\1/g

While I am a huge vi fan, I really dislike their regex syntax. To me, the JS syntax feels cleaner (not so many \ escapes) and more advanced (more character groups, and other features, though I could be mistaken here).

The only negatives I have encountered are:

  1. If you are expecting vi regex syntax, you might get a little frustrated (took me a while to realize this)
  2. I cannot figure out how to add a newline in the substitution string (\r in a vi substitute)
    According to vscode release notes, this was added to their built-in find/replace

@Chillee
Copy link
Member

Chillee commented May 24, 2017

This is added with the new "enableNeovim" option (on master).

@mathemaphysics
Copy link

I might also add here that the whole match character, '&' in vim, is actually '$&' in JS. I found this out through trial and error.

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

Successfully merging a pull request may close this issue.

7 participants