Welcome to Knit, a command-line text editor written in Kotlin.
In this personal project, I build my own text editor with only basic features, using Kotlin.
Note
- I started this project for learning purposes. Please do not use Knit for serious editing work—but feel free to play around with it!
- I’m writing a tutorial on how to craft a text editor in Kotlin. I’ll announce it on my blog (mtkrm.com) once it’s ready.
Screen.Recording.2025-02-19.at.15.43.07.mov
Knit uses a doubly-linked list to manage its text buffer. Each line of text is stored as a node in the list. This allows efficient insertion and deletion between lines while modifying a line can be expensive.
Hello, World!
This is Knit.
Goodbye!
+-------------------------+ +-------------------------+ +---------------------+
| Line 1 | <-> | Line 2 | <-> | Line 3 |
| "Hello, World!" | | "This is Knit." | | "Goodbye!" |
| prev: null | | prev: Line 1 | | prev: Line 2 |
| next: Line 2 | | next: Line 3 | | next: null |
+-------------------------+ +-------------------------+ +---------------------+
-
Generate the JAR File
- After cloning this repo, run:
./gradlew shadowJar
- The JAR file (e.g.
knit-0.1.jar
) will be generated in thebuild/libs/
folder.
- After cloning this repo, run:
-
Run the JAR File
- In the terminal, run:
java -jar build/libs/knit-1.0.jar
- This will launch Knit in your terminal.
- In the terminal, run:
-
Arrows
- Supports up, down, left, and right arrow keys.
- Missing support for jump moves (Command + arrow keys).
-
Text Input
- Inserts characters at the cursor position.
-
Commands
- Supports Enter/Line Feed, Carriage Return, and Delete.
- Missing support for saving the text buffer to a designated file (currently, it only displays the buffer).
- Missing support for Quit, Save, Exit, and many other commands.
-
Ambitious Goals
- Undo/redo functionality.
- Copy/paste functionality.
- Syntax highlighting.
- Main application logic:
Main.kt
,EditorApp.kt
- User input handling:
controller/
- State management:
managers/
- Data models:
models/
- Testing: tests for controllers are located in
src/test/kotlin/controller/