Light Weight UTF-8 Terminal Text Editor
A spiritual descendant of mg (Micro Emacs) — same Emacs heritage, about half the lines of code. See mg's README for the wider Emacs-in-a-terminal family kg comes from.
kg is a small, fast terminal text editor with pure Emacs keybindings. Suitable for editing system files or quick fixes on remote systems where a full GUI editor is not available.
With syntax highlighting for many languages, multiple buffers, split windows, incremental search, and multi-level undo, kg punches above its weight while staying dependency-free — no curses, just standard VT100 escape sequences.
Features
- Pure Emacs-style keybindings
- Syntax highlighting for many programming languages, including hex/binary/octal integer literals
- Multiple buffers with shared kill ring
- Split-window support
- Visual mark mode: the region renders in reverse video as you move
- Shift-select and the CUA clipboard trio (Shift-Delete / Ctrl-Insert / Shift-Insert) alongside the Emacs C-w / M-w / C-y
- Rectangle commands (C-x SPC, C-x r {k,y,d,c})
- Incremental search and query-replace (M-%)
- Multi-level undo (C-_)
- Paragraph reflow to 72 columns (M-q)
- Keyboard macros (C-x ( / C-x ) / C-x e)
- M-x, C-x C-f, and C-x b all share an ido-style picker: substring matching, already-open files pushed to the back of the file picker
- Detects external changes to open files; optional auto-revert
- Shell commands (M-!) and pipe-region-through-command (M-|)
- Comment-dwim (M-;)
- Word-case bindings (M-u / M-l / M-c)
- Open line (C-o) and join-line (M-^)
- Quoted-insert (C-q) for literal Tab/Esc/control bytes
- Universal-argument (C-u) for repeated commands
- Auto-indent and bracket autocomplete
- Suspend to background (C-z)
- Built-in help in a scrollable help buffer (C-h)
- No dependencies (not even curses)
- Uses standard VT100 escape sequences
- Graceful terminal resize handling
Usage
kg [-RVh] [file ...]
| Option | Description |
|---|---|
-R |
Open file(s) read-only |
-V |
Print version and exit |
-h |
Print this help and exit |
Multiple files can be opened at once, each in its own buffer. See the man page for more in-depth information as well as the full key binding reference.
Building and Installing
make
sudo make install # installs to /usr/local/bin and /usr/local/share/man/man1
Override the prefix or use DESTDIR for staged installs:
make install prefix=/usr
make install DESTDIR=/tmp/pkg
To uninstall:
sudo make uninstall
Origin & References
kg is based on kilo by Salvatore Sanfilippo (antirez), the original minimal text editor that demonstrates how to build a functional editor without dependencies in about 1000 lines of C code.
The name "kg" is a nod to mg (Micro Emacs), suggesting "kilo-gram" — a minimal implementation with Emacs keybindings. mg's README is the place to read up on the broader lineage if the heritage matters to you.
Copyright (c) 2016-2025, Salvatore Sanfilippo <antirez at gmail dot com> Copyright (c) 2026, Joachim Wiberg <troglobit at gmail dot com> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

