Skip to content

Instantly share code, notes, and snippets.

@brfitzpatrick
Created July 24, 2017 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brfitzpatrick/68ccaffdda5c204e4d775ec2d08877c1 to your computer and use it in GitHub Desktop.
Save brfitzpatrick/68ccaffdda5c204e4d775ec2d08877c1 to your computer and use it in GitHub Desktop.
swap values in emacs
M-x replace-regexp <RET>
\(dog\)\|cat <RET>
\,(if \1 "cat" "dog") <RET>
Beginning Line 3 with `\,` tells Emacs that this line should be evaluated as a Lisp expression.
The `\1` on Line three referres to the first grouped of characters defined with `(` and `)` on line 2.
Read line 3 as if `\1` replace with "cat" else replace with "dog"
You have to escape (i.e. preceed with `\`) the `(`, `)` and `|` characters for them to be treated as special characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment