A simple text editor implemented in Zig 0.13
, inspired by the functionality of Vim. Learning POC,building a simple text editor from scratch using the Zig.
- Normal Mode: Navigate and manipulate text without inserting characters.
- Insert Mode: Type and edit text directly.
- Command Mode: Execute commands for saving and quitting (:q, :w :i)
- Terminal UI: Render the text buffer and handle user input in the terminal.
- No Dependencies, No Libs, No Frameworks, No C
- Purelly written in Zig
- Self-contained
- ~380 LoC
To build the text editor, navigate to the project directory and run:
zig build
After building, you can run the text editor with:
./zig-out/bin/zim
or just do:
zig build run
This are the flags used to set the terminal to raw mode, allowing for direct control over input and output without interference from the terminal driver. This is crucial for implementing a text editor that behaves like Vim.
raw.lflag.ECHO = false
- Prevents typed characters from appearing automatically (you control what's displayed)raw.lflag.ICANON = false
- Allows reading single characters instead of waiting for Enterraw.lflag.ISIG = false
- Prevents Ctrl+C from killing your program (you handle ESC instead)raw.lflag.IEXTEN = false
- Disables extended input processingraw.iflag.IXON = false
- Disables software flow control (Ctrl+S/Ctrl+Q)raw.iflag.ICRNL = false
- Prevents automatic CR to LF conversionraw.iflag.BRKINT = false
- Disables break signalraw.iflag.INPCK = false
- Disables parity checkingraw.iflag.ISTRIP = false
- Disables stripping of 8th bitraw.oflag.OPOST = false
- Disables output processing