# Comby : structural code search and replace

**URL:** <https://discuss.kakoune.com/t/comby-structural-code-search-and-replace/1741>\
**Category:** Terminal Tools\
**Created:** [May 25, 2021, 11:50am UTC](https://discuss.kakoune.com/t/comby-structural-code-search-and-replace/1741 "2021-05-25T11:50:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Delapouite](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/delapouite/32/10_2.png) [@Delapouite](https://discuss.kakoune.com/u/Delapouite)\
**Post date:** [May 25, 2021, 11:50am UTC](https://discuss.kakoune.com/t/comby-structural-code-search-and-replace/1741/1 "2021-05-25T11:50:34Z")

</div>

Hello

> **[Comby · Structural code search and replace for ~every language.](https://comby.dev/)**
>
> Structural code search and replace for ~every language.

Here’s an example of what can be achieved:

```auto
comby 'failUnlessEqual(:[a],:[b])' 'assertEqual(:[a],:[b])' example.py

```

```auto
--- 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](https://discuss.kakoune.com/t/semgrep-semantic-grep/1624) that is a nice companion to Kakoune regexp primitives.

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [May 26, 2021, 6:31pm UTC](https://discuss.kakoune.com/t/comby-structural-code-search-and-replace/1741/2 "2021-05-26T18:31:19Z")

</div>

Feels a bit like [Ruplacer](https://discuss.kakoune.com/t/ruplacer-find-and-replace-text-in-source-files/1499) – and by a bit, I mean a lot. 🙂

---

<div class="post-metadata">

**Author:** ![eyepatchOwl](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/eyepatchowl/32/735_2.png) [@eyepatchOwl](https://discuss.kakoune.com/u/eyepatchOwl)\
**Post date:** [May 28, 2021, 2:16am UTC](https://discuss.kakoune.com/t/comby-structural-code-search-and-replace/1741/3 "2021-05-28T02:16:01Z")

</div>

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++.

---

<div class="post-metadata">

**Author:** ![JacobTravers](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jacobtravers/32/848_2.png) [@JacobTravers](https://discuss.kakoune.com/u/JacobTravers)\
**Post date:** [June 2, 2021, 8:18pm UTC](https://discuss.kakoune.com/t/comby-structural-code-search-and-replace/1741/4 "2021-06-02T20:18:07Z")

</div>

Another similar project is [ms-jpq/sad](https://github.com/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.
