Issue #212 resolved

When using substitution, allow & (ampersand) to refer to the matched pattern

Patrick Brinich-Langlois avatarPatrick Brinich-Langlois created an issue

In Vim, if you want to add something to a pattern (such as adding an "@" symbol at the beginning of a variable name to make it an instance variable in Ruby), you can do this:

:%s/foobar/@&

The ampersand stands for the matched pattern, "foobar." I know that you can do this

:%s/\(foobar\)/@\1

but it requires more typing.

Comments (4)

  1. Frank Fischer

    (Reply via fran...@mathematik.tu-chemnitz.de):

    Am Tue, 23 Oct 2012 20:08:25 -0000 schrieb Patrick Brinich-Langlois issues-reply@bitbucket.org:

    I didn't know that a plain & can be used. Currently you can use \& (with a backslash) to achieve the desired behavior. So probably the meaning of & and \& are inverse, currently. But it should not be too difficult to fix.

  2. Frank Fischer

    Support vim style magic characters in patterns and replacements

    Magic characters are now transformed in a generic way to Emacs patterns/replacements. Whether a certain magic character requires a backslash is determined by the `evil-magic' customization variable.

    This fixes #212.

    → <<cset 94627aeaf6ae>>

  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.