TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Codex – Find and Replace for Code

42 pointsby gushogg-blakeover 2 years ago
Most code editors&#x27; find &amp; replace features are still very close to the original design intended for text documents, so they become unwieldy when you need to match across newlines and indentation for example, or when a parse of the code is necessary to capture a particular expression.<p>Codex (<a href="https:&#x2F;&#x2F;codex-kappa-dusky.vercel.app&#x2F;" rel="nofollow">https:&#x2F;&#x2F;codex-kappa-dusky.vercel.app&#x2F;</a>) is an attempt to rethink what find &amp; replace should look like in a modern code editor. It defines a simple but powerful syntax for describing code modifications, combining plain text, regular expressions and Tree-sitter queries, along with sensible handling of newlines and indentation*.<p>It can be used just like regular plain text find &amp; replace, but allows freely mixing in regexes and Tree-sitter queries as more flexibility is needed.<p>It introduces &quot;line quantifiers&quot; for matching a bunch of lines at the same nesting level, so basic structural changes can be achieved without even using a query (see the JavaScript function example in the link).<p>I designed Codex with a specific use case in mind (the one I show in my demo video: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=MQ_N0-AJ2Qg">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=MQ_N0-AJ2Qg</a>), so any suggestions for other things it should support would be much appreciated, as well as general feedback.<p>*Indentation is relative and space&#x2F;tab agnostic.

6 comments

counttheforksover 2 years ago
Cool! Are you familiar with jetbrains&#x27;s structural search &amp; replace? The way it works is quite intuitive. Might be worth mentioning as a comparison.<p><a href="https:&#x2F;&#x2F;www.jetbrains.com&#x2F;help&#x2F;idea&#x2F;structural-search-and-replace.html" rel="nofollow">https:&#x2F;&#x2F;www.jetbrains.com&#x2F;help&#x2F;idea&#x2F;structural-search-and-re...</a>
评论 #34462373 未加载
评论 #34450898 未加载
fizxover 2 years ago
I&#x27;ve often wanted to extend the <a href="https:&#x2F;&#x2F;selectorgadget.com" rel="nofollow">https:&#x2F;&#x2F;selectorgadget.com</a> algorithm to be able to do find &amp; replace on code ASTs, instead of the DOM tree.<p>It&#x27;d be pretty cool to be able to find-by-example, selecting snippets of code and having the algorithm tell you what they all have in common.
gregwebsover 2 years ago
This looks neat, how do I try it out? Semgrep is nice for simple modifications but poor at multi line. Comby works well a lot of the time but I really need something more sophisticated. More sophisticated often means language specific but I would like to have a language independent tool like this.
评论 #34438190 未加载
评论 #34446928 未加载
sixstringtheoryover 2 years ago
Regex search and replace is table stakes for a code editor. All the way back to ed ;-)<p>Tree-sitter queries is an interesting addition. That and bazel build system queries seem like a step up in editing and compiling code.
joshkaover 2 years ago
Meta-note: do you have any concerns about overloading the name &quot;Codex&quot;? There are quite a few software products and companies named this.<p>This is pretty cool. I wonder though if the tree sitter query syntax is the right thing to directly expose. This is definitely useful beneath the hood for people writing specific refactoring patterns, but it would seem overkill for general dev. Is there some syntax that looks closer to regexes for this (tree sitter inside regex rather than regex inside tree sitter)?<p>I wonder if attacking this problem at one level up say the LSP level could be a good idea.
评论 #34438055 未加载
评论 #34436123 未加载
评论 #34441008 未加载
评论 #34436456 未加载
ttcbjover 2 years ago
This is interesting, but to be honest it’s more learning than I personally want to take on for this use case.<p>One feature that I miss from code editors is “record actions”. The last time I remember having it was maybe in visual studio around the late 90s. It would record whatever you did (keystrokes&#x2F;copy paste&#x2F;find replace&#x2F;etc). At that time, I found that I could often address use cases similar to those I think you are targeting by thoughtfully recording the right sequence of actions.
评论 #34438275 未加载
评论 #34447069 未加载
评论 #34435721 未加载
评论 #34438219 未加载