Comby : structural code search and replace

Hello

Here’s an example of what can be achieved:

comby 'failUnlessEqual(:[a],:[b])' 'assertEqual(:[a],:[b])' example.py
--- example.py
+++ example.py
@@ -1,6 +1,6 @@
     def test(self):
         r = self.parse("if 1 fooze", 'r3')
-        self.failUnlessEqual(
+        self.assertEqual(
             r.tree.toStringTree(),
             '(if 1 fooze)'
             )

More examples are available in the documentation.

Comby is a tool that in the same vein than Semgrep that is a nice companion to Kakoune regexp primitives.

4 Likes

Feels a bit like Ruplacer – and by a bit, I mean a lot. :slight_smile:

I mean… Ruplacer is regex based I think?

I tried out comby, but it would need some extension to be good as a matcher, and it doesn’t appear to support C++.

Another similar project is ms-jpq/sad or “Space Age seD”.
It uses fzf and your diff-highlighter to view/choose replacements. So far it’s the best replacement I’ve found for the interactive find/replace you get in IDE’s.