Reputation: 3103
This is something easily done in nedit, or komodo, but could not find how to do it in emacs.
I highlight an area of my code, using the mouse. Then I just want to do replace or regexp replace, on the area highlighted only.
Any ideas?
A reference to elisp code which enables this is more than welcome.
Thanks.
Upvotes: 1
Views: 189
Reputation: 17003
Use the command query-replace
(by default it is bound to M-%
), or M-x query-replace
. If a region is highlighted, it will only do replacements within that region.
If you want to use a regexp, do M-x replace-regexp
with a region highlighted, and you will have the same behavior.
However, keep in mind that when you are in windowless Emacs in the terminal, this will not work with mouse selection. You can still mark/highlight a region with keyboard commands, and then replacements will only be applied to that region, but if you highlight a region with the mouse, although it will visually be highlighted, Emacs will not treat it as a marked/highlighted region. As far as I know, there is no way around this fact in windowless Emacs.
Upvotes: 2