Top Related Projects
Quick Overview
Kilo is a small text editor written in less than 1000 lines of C code. It's designed to be a minimalistic and educational project, demonstrating how to build a basic text editor from scratch without relying on any library beyond the standard C library.
Pros
- Extremely lightweight and fast
- Educational resource for learning low-level text editor implementation
- Easy to understand and modify due to its small codebase
- No dependencies beyond the standard C library
Cons
- Limited features compared to full-fledged text editors
- No syntax highlighting or advanced editing capabilities
- Not suitable for large-scale text editing tasks
- Lacks cross-platform support (primarily designed for Unix-like systems)
Code Examples
- Reading a keypress:
int editorReadKey() {
int nread;
char c;
while ((nread = read(STDIN_FILENO, &c, 1)) != 1) {
if (nread == -1 && errno != EAGAIN) die("read");
}
return c;
}
This function reads a single keypress from the standard input.
- Clearing the screen:
void editorRefreshScreen() {
write(STDOUT_FILENO, "\x1b[2J", 4);
write(STDOUT_FILENO, "\x1b[H", 3);
}
This function clears the screen using ANSI escape sequences.
- Moving the cursor:
void editorMoveCursor(int key) {
switch (key) {
case ARROW_LEFT:
if (E.cx != 0) E.cx--;
break;
case ARROW_RIGHT:
if (E.cx != E.screencols - 1) E.cx++;
break;
case ARROW_UP:
if (E.cy != 0) E.cy--;
break;
case ARROW_DOWN:
if (E.cy != E.screenrows - 1) E.cy++;
break;
}
}
This function handles cursor movement based on arrow key input.
Getting Started
To get started with Kilo:
-
Clone the repository:
git clone https://github.com/antirez/kilo.git
-
Compile the source code:
cd kilo make
-
Run the editor:
./kilo [filename]
Use Ctrl-Q to quit, Ctrl-S to save, and arrow keys to navigate.
Competitor Comparisons
The hacker's browser.
Pros of Vimium
- Browser-based: Enhances web browsing experience with Vim-like shortcuts
- Extensive feature set: Offers a wide range of navigation and control options
- Active community: Regular updates and contributions from users
Cons of Vimium
- Limited to web browsers: Not a standalone text editor like Kilo
- Steeper learning curve: Requires familiarity with Vim-style commands
- Dependency on browser compatibility: May have limitations based on browser support
Code Comparison
Kilo (C):
void editorMoveCursor(int key) {
switch (key) {
case ARROW_LEFT:
if (E.cx != 0) {
E.cx--;
}
break;
// ... other cases
}
}
Vimium (JavaScript):
const scrollToBottom = () => {
window.scrollTo(0, document.body.scrollHeight);
};
Vomnibar.activate = (options = {}) => {
const vomnibar = new Vomnibar(options);
vomnibar.init();
};
While Kilo focuses on low-level text editing operations in C, Vimium implements browser-specific actions in JavaScript, reflecting their different purposes and environments.
A modern and intuitive terminal-based text editor
Pros of micro
- More feature-rich, including syntax highlighting and multiple buffers
- Actively maintained with regular updates and improvements
- Extensive plugin system for customization and extensibility
Cons of micro
- Larger codebase and more complex architecture
- Higher resource usage due to additional features
- Steeper learning curve for users and contributors
Code comparison
micro (Go):
func (t *TextArea) Insert(c rune) {
t.insertAtCursor(string(c))
t.cursor.Right()
}
kilo (C):
void editorInsertChar(int c) {
if (E.cy == E.numrows) {
editorInsertRow(E.numrows, "");
}
editorRowInsertChar(&E.row[E.cy], E.cx, c);
E.cx++;
}
Summary
micro is a more feature-rich and actively maintained text editor, offering syntax highlighting, multiple buffers, and an extensive plugin system. However, it has a larger codebase and higher resource usage compared to kilo. kilo, on the other hand, is a minimalist editor with a simpler codebase, making it easier to understand and modify but lacking some advanced features. The code comparison shows the difference in implementation languages and complexity between the two projects.
A lightweight text editor written in Lua
Pros of lite
- Written in Lua, offering easier extensibility and customization
- Includes a plugin system for adding new features
- Provides a more modern and feature-rich text editing experience
Cons of lite
- Larger codebase and more complex architecture
- Requires Lua runtime, potentially impacting portability
- May have a steeper learning curve for contributors
Code comparison
lite (Lua):
local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
command.add("core.docview", {
["file:open"] = function()
core.command_view:enter("Open File", function(text)
core.root_view:open_doc(core.open_doc(text))
end)
end,
})
kilo (C):
void editorProcessKeypress() {
int c = editorReadKey();
switch (c) {
case CTRL_KEY('q'):
write(STDOUT_FILENO, "\x1b[2J", 4);
write(STDOUT_FILENO, "\x1b[H", 3);
exit(0);
break;
}
}
mawww's experiment for a better code editor
Pros of Kakoune
- More feature-rich and advanced text editor with modal editing
- Supports multiple selections and interactive filtering
- Active development and community support
Cons of Kakoune
- Steeper learning curve due to its unique editing paradigm
- Larger codebase and more complex architecture
- Requires more system resources compared to Kilo
Code Comparison
Kilo (main editing loop):
while(1) {
editorRefreshScreen();
editorProcessKeypress();
}
Kakoune (main event loop):
while (true)
{
try
{
context.events_manager().handle_next_event(context);
}
catch (runtime_error& error)
{
context.print_status({error.what(), get_face("Error")});
}
}
Kilo is a minimalist text editor designed for simplicity and educational purposes, while Kakoune is a more advanced text editor with a unique selection-oriented editing model. Kilo's codebase is smaller and easier to understand, making it ideal for learning about text editor internals. Kakoune offers more features and flexibility but requires more effort to master. The code comparison shows the difference in complexity between the two projects' main loops, with Kakoune handling events and errors more robustly.
Vim-fork focused on extensibility and usability
Pros of Neovim
- Extensive plugin ecosystem and customization options
- Active development with frequent updates and new features
- Built-in Lua support for scripting and configuration
Cons of Neovim
- Steeper learning curve due to complexity and numerous features
- Larger codebase and resource footprint
Code Comparison
Kilo (simple text insertion):
void editorInsertChar(int c) {
if (E.cy == E.numrows) {
editorInsertRow(E.numrows, "", 0);
}
editorRowInsertChar(&E.row[E.cy], E.cx, c);
E.cx++;
}
Neovim (text insertion with API):
local api = vim.api
local function insert_char(char)
local row, col = unpack(api.nvim_win_get_cursor(0))
api.nvim_buf_set_text(0, row - 1, col, row - 1, col, {char})
api.nvim_win_set_cursor(0, {row, col + 1})
end
Summary
Kilo is a minimalist text editor designed for educational purposes, while Neovim is a feature-rich, extensible editor for daily use. Kilo offers simplicity and a smaller codebase, making it easier to understand and modify. Neovim provides a more powerful editing experience with advanced features and plugin support, but at the cost of increased complexity.
The official Vim repository
Pros of vim
- Extensive feature set with powerful editing capabilities
- Large ecosystem of plugins and customizations
- Cross-platform support and wide availability
Cons of vim
- Steep learning curve for new users
- Complex codebase with a long history, making it harder to contribute
- Larger resource footprint compared to minimal editors
Code Comparison
Vim (handling key input):
static void normal_cmd(oparg_T *oap, int toplevel)
{
int c;
int cc;
int nchar;
int command_executed = FALSE;
// ...
}
Kilo (handling key input):
void editorProcessKeypress() {
int c = editorReadKey();
switch (c) {
case CTRL_KEY('q'):
exit(0);
break;
// ...
}
}
The code snippets show how each editor handles key input. Vim's approach is more complex, reflecting its advanced functionality, while Kilo's implementation is simpler and more straightforward.
Vim offers a rich set of features and extensibility but comes with a steeper learning curve. Kilo, being a minimal editor, provides a simpler codebase and easier entry point for beginners or those looking to understand editor internals.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Kilo
Kilo is a small text editor in less than 1K lines of code (counted with cloc).
A screencast is available here: https://asciinema.org/a/90r2i9bq8po03nazhqtsifksb
Usage: kilo <filename>
Keys:
CTRL-S: Save
CTRL-Q: Quit
CTRL-F: Find string in file (ESC to exit search, arrows to navigate)
Kilo does not depend on any library (not even curses). It uses fairly standard VT100 (and similar terminals) escape sequences. The project is in alpha stage and was written in just a few hours taking code from my other two projects, load81 and linenoise.
People are encouraged to use it as a starting point to write other editors or command line interfaces that are more advanced than the usual REPL style CLI.
Kilo was written by Salvatore Sanfilippo aka antirez and is released under the BSD 2 clause license.
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot