Gram is a lightweight, terminal-based text editor written in C, inspired by Kilo. It provides essential text editing functionalities while maintaining a minimalistic and efficient codebase.
- Basic text editing operations.
- Handles input, output, and cursor movements.
- Relative line numbering for better navigation.
- Jump up/down by N lines using shortcut keys.
- Syntax highlighting (optional).
- Small codebase (~1000 lines of C).
- Runs in a terminal (Linux/macOS support).
- No external dependencies.
Clone the repository and compile the source code using gcc:
git clone https://github.com/yourusername/gram-text-editor.git
cd gram-text-editor
gcc gram.c -o gram -Wall -Wextra -pedantic -std=c99Then, run it:
./gram filename.txtOnce inside Gram, you can use the following keybindings:
| Command | Description |
|---|---|
Ctrl + S |
Save file |
Ctrl + Q |
Quit the editor |
Ctrl + F |
Find text in the file |
Arrow Keys |
Move cursor |
Backspace |
Delete character before cursor |
Enter |
Insert new line |
Ctrl + U |
Jump up N lines (configurable) |
Ctrl + D |
Jump down N lines (configurable) |
📂 gram-text-editor
├── gram.c # Main source file
├── gram.h # Header file
├── Makefile # Build system
├── README.md # Documentation
The editor disables canonical mode using tcgetattr() and tcsetattr(), allowing real-time keypress reading.
Gram reads user input character-by-character and processes commands accordingly.
- The editor tracks cursor position and displays relative line numbers.
- Implements jumping functionality (
Ctrl + U/Ctrl + D) to move N lines at once.
- It loads a file into memory when opened.
- Saves modifications back to disk when needed.
Instead of manually compiling, you can use a Makefile:
CC = gcc
CFLAGS = -Wall -Wextra -pedantic -std=c99
gram: gram.c
$(CC) $(CFLAGS) gram.c -o gram
clean:
rm -f gramBuild and run:
make
./gram filename.txt- Relative numbering
- Jump N lines up/down
- Add syntax highlighting.
- Implement undo/redo functionality.
- Line numbering toggle support.
- Mouse support for selection.
- Windows support.
Pull requests and suggestions are welcome! Feel free to fork the repo and submit improvements.