LinuxCommandLibrary

comby

structural code search and replace tool

TLDR

Simple replacement

$ comby 'console.log(:[arg])' 'logger.info(:[arg])' [.js]
copy
Replace in directory
$ comby 'foo(:[x])' 'bar(:[x])' [src/] -matcher [.py]
copy
Preview changes
$ comby 'old' 'new' -match-only
copy
Interactive review
$ comby 'pattern' 'replacement' -review
copy
In-place modification
$ comby 'old' 'new' -in-place [file.go]
copy
Diff output
$ comby 'old' 'new' -diff [file.js]
copy

SYNOPSIS

comby matchtemplate rewritetemplate [path] [options]

DESCRIPTION

comby is a structural code search and replace tool for any language. Uses lightweight templates with holes (:[name]) to match code structures. Understands syntax of code blocks, strings, and comments.

PARAMETERS

-matcher ext

File extension matcher (.py, .js, etc.)
-match-only
Only show matches, don't rewrite
-in-place
Modify files in place
-diff
Show unified diff output
-review
Interactive review mode
-stdin
Read from stdin
-stdout
Write to stdout
-count
Count matches only
-d dir
Target directory

HOLE SYNTAX

:[name]

Match any expression
:[name:e]
Match balanced expression
:[[name]]
Match across lines
:[_]
Anonymous hole (discard)

CAVEATS

Better than regex for nested structures. Does not support indentation-sensitive languages (Python, Haskell).

SEE ALSO

sed(1), ast-grep(1), semgrep(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community