philipp's blog

hecto: Build Your Own Text Editor in Rust

🏗️ Construction Notice

The old (complete, but outdated) version of hecto is available here. You are looking at the 2024 version of hecto, which is still unfinished. You can follow the progress of the rewrite here. Once it’s done, this notice will be deleted.


Welcome! This is a series of blog posts that shows you how to build a text editor in Rust.

It's a re-implementation of antirez' kilo in Rust, and a remix of Paige Ruten's tutorial for the same thing in C. It’s somewhere around 1000 lines of Rust in a few files with a few dependencies, and it implements all the basic features you expect in a minimal editor, as well as syntax highlighting and a search feature.

These posts walk you through building the editor and learning Rust in multiple small steps. For the first steps, you’ll add, change, or remove a few lines of code. Most steps, you’ll be able to observe the changes you made by compiling and running the program immediately afterwards. Once you’ve built up a solid understanding of Rust, you’ll get a description of what to solve next and have the opportunity to try it out before you compare it to my own take on the solution1.

I wrote this tutorial coming from a different corner of the engineering world, to obtain a deep understanding of Rust. If you’re in a similar situation, this tutorial is for you.

I explain each step along the way, sometimes in a lot of detail, and definitely not always Rust-related. Feel free to skim or skip the prose2, as the main point of this is that you are going to build a text editor from scratch while learning Rust! Anything you learn along the way is bonus, and there’s plenty to learn just from typing in the changes to the code and observing the results.

See the appendices for more information on the tutorial itself (including what to do if you get stuck, and where to get help).

If you’re ready to begin, then go to chapter 1!

Table of Contents

This post was last updated 6 days, 3 hours ago.

  1. But if you wish to just read instead of coding yourself, that’s fine too.

  2. This tutorial is long, and very deliberately so. If you want to build the same text editor in Rust, but with less prose and less sidetracking, have a look at pound by Kofi Otuo. However, once we get to the point where I create assignments for you, it will be easier for you to skip explanations and just go from one assignment to the next.

#hecto