In vim, all instances of an apple tree
can be replaced by an orange tree
with :%s/an \zsapple\ze tree/orange/g
.
\zs
and \ze
mark the start and end of the passage to be operated on.
Is there something equivalent in emacs?
As far as I know, evil mode needs the much less elegant
:%s/\(an \)\(apple\)\( tree\)/\1orange\3/g
Asked
Active
Viewed 586 times
6

Toothrot
- 3,264
- 1
- 13
- 32
1 Answers
1
You could use M-x query-replace-regexp
and use apple\( tree\)
as search text and orange\1
as replacement.
query-replace-regexp
will search for the first string and will ask you to replace the second string. You can use the exclamation mark !
to replace all of them without further questions.
\ze
and\zs
are supposed to do. – Dan Dec 23 '16 at 16:15