Is it possible to perform a replace-string operation inside of a rectangular region in emacs? If so, how?
Is it possible to perform a replace-string operation inside of a rectangular region in
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you enable CUA selection mode:
M-x
cua-selection-modeRETor permanently in your init file:
You can then use its advanced rectangle editing facilities.
(or if you’re a
cua-modeuser, then you don’t need to do that.)For documentation, look for the “CUA rectangle support” heading in the commentary in M-x
find-libraryRETcua-baseRETIf you don’t want to use the cua rectangle facilities for some reason (perhaps if you really need
replace-stringspecifically), a custom function usingapply-on-rectanglewould be pretty simply to put together.Edit: Actually, slightly more complex than I had expected, but most of the code is the interactive spec and the support for the ‘delimited’ prefix argument behaviour (both based on
replace-string).Edit 2: I decided this was worth doing in a more fully-featured manner:
The following provides C-xrM-% and C-xrC-M-%, which (hopefully) act the way you would expect.