3 ms·
That first trick in the video - select some text, do multi-site replacement - how do I do this in Emacs (35 year user, but have no idea :)
by PaulDavisThe1st 5y ago
That first trick in the video - select some text, do multi-site replacement - how do I do this in Emacs (35 year user, but have no idea :)
- jimm 5y agoIf you select a region with transient mode on, then `query-replace` (`M-%` by default) will only affect the region. So select the region you want the change to effect (just like in the demo video), hit `M-%`, then type the old and new text, then you can type `!` when prompted for what to do and all instances of old become new only within the region.
- natrys 5y agoThere is multiple cursors[1]. Checkout the video by emacsrocks[2]. You can combine that with regex tools if you need to do this over complex patterns[3]. There is also iedit which may fit your mental model better[4]. [1] https://github.com/magnars/multiple-cursors.el https://github.com/magnars/multiple-cursors.el [2] http://emacsrocks.com/e13.html http://emacsrocks.com/e13.html [3] https://github.com/benma/visual-regexp-steroids.el https://github.com/benma/visual-regexp-steroids.el [4] https://github.com/victorhge/iedit https://github.com/victorhge/iedit
- arc-in-space 5y agohttps://streamable.com/t4i5tx https://streamable.com/t4i5tx The highlights and fancy replacement preview are added by a plugin called anzu[0], but otherwise this is a standard emacs feature. I couldn't tell you what the default binding is but the function is query-replace-regexp. (I don't understand why people are trying to bring multiple cursors into this) [0] https://github.com/emacsorphanage/anzu https://github.com/emacsorphanage/anzu
- PaulDavisThe1st 5y agoI use replace-replace-regexp a lot. What was shown in the video was qualitatively different. Multiple sites were shown changing at the same time. That's not what q-r-r does, even with "bang" version mentioned above. You could actually see the old text replaceable by the being-entered new text.
- karthink 5y agoThe buffer was not being edited when the replacement was shown to be happening. The plugin anzu uses overlays[1] to show the text being replaced and the replacements. [1]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Overlays.html https://www.gnu.org/software/emacs/manual/html_node/elisp/Ov...