3 ms·
This is really nice, but for me there's one thing that keeps me away from emacs, and its good multi cursor support. Very frequently, I'll want to perform this
by FemmeAndroid 5y ago
This is really nice, but for me there's one thing that keeps me away from emacs, and its good multi cursor support.
Very frequently, I'll want to perform this kind of process:
1. I search for some frequently occurring string or regex in a file.
2. Get a series of cursors for every result of that search.
3. I'll know that it's possible to do a manipulation of all these lines, but frequently it's not immediately obvious how, so I experiment a bit at this point. Frequently I end up doing things like manipulating the cursor to delete sections of the line, and modify the shape and order of some elements. This requires I can select portions of text, cut them, and paste them in a different part of the line. So each cursor needs to have its own clipboard. I also tend to do things like add variables to the cursors. Sublime has a nice way to have incrementing integers so the first cursor inserts a 1, the second inserts a 2, etc. There are all sorts of little tricks like this. One appeal of something like emacs would be having a simple language to write stuff like this quickly myself.
4. After experimenting, I complete the manipulation. If I fail the first time, I undo, and do it again.
This kind of thing takes less than 15 seconds for me, but it saves a ridiculous amount of time.
It's really useful during this to actually be manipulating all lines at once, since it lets me see where assumptions I have about the data I'm manipulating is incorrect.
I've tried every multi cursor package I've seen in emacs, and I've tried to figure out how to get this kind of thing down through macros, but the live editing of multiple lines seems invaluable and keeps me in Sublime/VS Code. I'd love to know if I'm doing something wrong with macros, there's a solution to what I'm trying to do, or if realistically my best bet is to stick to what I know.
- CyberShadow 5y agoI have not tried the multiple cursors package, but regarding the problem of manipulating several lines at once with instant preview, you could look at the visual-regexp package: https://github.com/benma/visual-regexp.el https://github.com/benma/visual-regexp.el
- hsbauauvhabzb 5y agoTry macro record / macro playback. While saying this I hate that I’ve never properly learned how to debug a recorded macro, or manage them better, but they largely suit my use cases.
- srcreigh 5y agoI always use regexp-replace for this. There's an incrementing counter for regexp-replace, a way to manually enter a part of each replacement, and other goodies. Personally I only use capture groups, no counters or other stuff. I do like using M-p to edit my previous failed replacement before trying again. Sometimes I use a simple replacement as a test, undo it, then edit it to add further modifications. https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Replace.html https://www.gnu.org/software/emacs/manual/html_node/emacs/Re...
- FemmeAndroid 5y agoThank you so much! This is exactly what I was looking to find out. I had no idea I could trigger custom behaviors like this using regexp-replace. I’m going to need to get quick with it, but this should be enough of a reason to really work on making the switch.