Sage

Published in 2024/11/04 - Source code

Sage is a small console-based text editor inspired by Vim and written in Rust.

The only external crate that it uses is Crossterm and it should work on multiple terminals.

Since it was just a small project for learning terminal manipulation, there is much room for improvement:

  • Motions:

    As it is now, motions are hard-coded since there is a small amount of them just for cursor movement. One idea that I had is to convert the motion handling in some sort of AST or a simpler parsing structure. That would allow Sage to evaluate more complex motions (e.g cw, di", y$) without needing to hardcode functions for each of them.

    For example, lets look at the motion di" (Delete Inside Quotes), as you may guess, this motion deletes all the text inside the next quotes.

    1. The key d doesn't do anything by itself, so pressing it should put it an AST, waiting the next presses to be evaluated together (like expressions in programming languages).
    2. The key i, unlike the previous one, enters Insert Mode when pressed alone. But in this case, it is being evaluated as part of an expression and should be pushed to the AST instead, asking for more key presses.
    3. The key " doesn't need a next one to be evaluated, so it is pushed to the AST and the chain of waiting next presses is stopped, allowing the program to evaluate the whole Motion.
    4. The evaluation would be something like: Delete (where?) Inside (where?) Quotes.

    The same logic can be applied to motions like yiw, dt&,ci(

  • Some other TODOs: Visual Mode, Yank/Paste, Undo/Redo, Mouse Capture, Syntax Highlighting and Text Search.

If you want to know more about Vim, there is great resources at:

And the source code inspirations for this small project: