Like global search and replace but don’t like surprises?

Check out serpl – a handy little command-line app that gives you a visual preview of the changes you are about to make. You can even go in and remove the replacements you don’t want from the source previews. The regex support appears to be basic, however (I couldn’t get a negative lookbehind to work).

https://github.com/yassinebridi/serpl#readme

(Also, it appears they’re looking for maintainers. It’s written in Rust.)

#searchAndReplace #findAndReplace #CLI #app #serpl #dev

@aral Please, my child is between life and death. Please repost.
@aral it uses the rust regex crate, which does not support lookaround or backreferences, because they "are not known how to implement efficiently"
regex - Rust

This crate provides routines for searching strings for matches of a regular expression (aka “regex”). The regex syntax supported by this crate is similar to other regex engines, but it lacks several features that are not known how to implement efficiently. This includes, but is not limited to, look-around and backreferences. In exchange, all regex searches in this crate have worst case `O(m * n)` time complexity, where `m` is proportional to the size of the regex and `n` is proportional to the size of the string being searched.

@ilmari 🤷‍♂️

(One person’s inefficient is another’s good enough.) ;)

@aral for those of you using #Emacs it has a similar feature that can be run with M-x occur. You can also run the M-x multi-occur command to do find/replace across multiple files.

In an occur-mode buffer, you can press e to enter “edit mode” and modify each matching line in place, then press C-c C-c to commit those changes to the file. This allows you to do search/replace using the ordinary C-M-% command.

@ramin_hal9001 @aral Emacs has a number of modes that let you edit stuff in buffers, and then apply the changes, including wdired and wgrep.

@rpluim yes, I use wdired all the time.

It is much, much more safe and reliable than using tools like mv when renaming things. When I need to rename files in the terminal, I often use the command emacs -nw -Q . to open the current directory and edit the filenames like I would a file. Plus you have access to copy/paste and find/replace and all the other usual editing tools you might need available to you as you choose your file names.

Wgrep is also nice, but I don’t think it comes with the standard set of built-in tools for Emacs, I think you have to install that one separately. Multi-occur is built-in so I tend to use that one.

@aral

@ramin_hal9001 @aral I guess you just have to reinvent emacs but in a way that they are not easily interlope-able...

I guess you just have to reinvent emacs but in a way that they are not easily interlope-able

@tusharhero what are you talking about?! You can use Unix pipes to make everything interoperable!!! (Sarcasm)

@aral

@ramin_hal9001 @aral That might be true for some programs. But most programs (TUI) are not at all designed for that.

Vim, for example, is not at all like that. I don't know if you can at least pipe buffer regions into programs or not, probably can. But that is something I do all the time inside Emacs.

(I know you are joking).

@tusharhero yes, you gleaned the point I was making exactly.

Terminal apps are basically like cell phone apps, where there is no attempt (beyond copy-paste, or simple message passing, like what Android OS calls “intents”) to make programs interoperable at all, because there is basically no infrastructure for it. I mean, sockets exist on most operating systems, but this just forces you to isolate functionality into a client-server architecture with well-defined protocols (DBus, for example), and a lot of these TUI app never even bother with such things. They are just GUIs that use ANSI terminal codes to draw things on screen.

They all operate in isolation, they all have their own unique command line syntax, their own unique configuration scripting syntax, their own unique user interface, you have to relearn everything for each TUI tool you decide to use.

To be fair, Lisp languages (e.g. Emacs) can be just as chaotic, but there is at least more of an attempt to unify all the disparate apps under a single configuration language and UI/UX philosophy. Everything can be scripted using the same, well-defined, turing-complete programming language, and messages are passed between apps using a well-structured and consistent protocol (S-expressions) that is built-in to the system itself.

@aral

@tusharhero @ramin_hal9001 @aral You definitely can pipe regions of a vim buffer to a command. I'd say it's even encouraged among vim users.