A toy text editor for X in around 500 lines of C.
Warning: This project is a toy meant for fun and has a lot of limitations. No guarantees to your input files.
make
sudo make install
Simplistic vim
-like bindings.
- Normal, Insert and Command modes.
- Arrow and Page keys to navigate.
- Normal mode commands: "i", "a", "o", "dd".
- Command mode: "w" to write and "q" to quit.
There are three primary/famous data structures to use for text-editing:
- Gap buffers, as used in Emacs.
- Ropes.
- Piece Tables.
Since, this is a toy and I wanted the simplest option, what I have done is the following:
- Model the file/buffer as a doubly linked list, where each entry is a single line.
- Model each line as single string.
- When switching to editing (normal -> insert), convert the current line into a line-scoped Gap buffer. This is used as long as you are in insert mode.
- When done editing the line (insert to normal), move back from the Gap buffer to a character array, a new allocation basically.
The selection of the doubly linked list is primarily to make adding and removing lines an easy operation.
MIT