Kitty Is the KDE of Terminal Emulators
Wayland King
Kitty is a wayland compatible, cross-platform, feature rich terminal emulator. A new kid on the block, the project started in 2017. I have used it since I switched to wayland, and it’s left me thoroughly impressed. After using it for 7 months, I don’t think I can go back to other terminal emulators.
Features
Kitty has a broad range of features that make it a joy to use. Some of these include, but aren’t limited to:
- GPU rendering
- Integrated terminal multiplexer
- Remote control
- An extension framework called kittens
- True color
- Native image support
- Font ligatures
- Hyperlink support
- Send scrollback buffer to
less
Terminal Multiplexing
Users who wanted to have multiple terminal sessions with panes and windows in one terminal emulator historically used tmux and GNU screen. Kitty has a mostly feature complete multiplexing solution built in. It breaks multiplexing functions into two components:
- Windows
- Tabs
Windows are like panes in tmux. To spawn them, hit ctrl-shift-enter. You can cycle through the windows in the active tab by hitting ctrl-shift-] and ctrl-shift-[ respectively. To move windows forwards and backwards, hit ctrl-shift-f and ctrl-shift-b respectively. You can even focus based on window id, for example, enter ctrl-shift-0 to focus on window 0. Kitty provides seven window layouts:
- Fat - The first window spawns full width at the top. Subsequent windows spawn side by side below the first window
- Grid - Equal sized windows tile next to each other
- Splits - Flexible layout enabling users to split from existing windows however they please
- Vertical - Windows spawn full width one on top of the other
- Horizontal - Windows spawn full height side by side
- Tall - The first window spawns full height on the left half of the screen. Subsequent windows spawn vertically on top of each other on the right half
- Stack - Displays a single full screen window at a time
Cycle through the layouts by hitting ctrl-shift-l. To close a window, hit ctrl-shift-w.
Tabs work like they do in other mainstream terminal emulators. They have a tmux-like appearance and are user customizable.
Kitty allows users to pre-define session layout through a dedicated session file. Kitty can use this file either through the --session
flag or by setting the file in kitty.conf with startup_session
option. You
can define the following parameters in the session file:
- Window layout or layouts for a given tab
- Working directory for the windows
- Number of windows in a tab and what programs run in them
- Number of tabs
- Number of OS windows
- The size of each OS window
GPU Rendering
Kitty offloads rendering to the GPU to provide smooth scrolling, low latency, and low CPU usage. To accomplish this, kitty stores a cache of each rendered glyph in video RAM so that font rendering is not a bottleneck. Kitty keeps latency low by using threaded rendering. Finally, interaction with child programs takes place in a separate thread from rendering, improving smoothness.
The use of OpenGL based rendering allowed package maintainers to port kitty to the BSDs with ease.
Image Support
Kitty supports images natively with the icat kitten. You can make icat a pseudo image viewer by adding this to your ~/.bashrc:
alias icat="kitty +kitten icat"
The terminal file manager ranger supports image previews with kitty. To enable this, add the following to ~/.config/ranger/rc.conf:
# Image previews
set preview_images true
set preview_images_method kitty
If that wasn’t enough, icat can handle animated gifs too!
Kittens
Kittens let users extend the functionality of kitty terminal. We just discussed icat, but there are other ones that ship with kitty by default. Users can create their own kittens too using python. To create a kitten, follow these steps:
- Create a file in ~/.config/kitty with the desired kitten name and .py appended to it
- Write the code for the kitten in your text editor of choice
- Map the kitten in your kitty.conf by adding
map keyofchoice kitten nameofkitten.py
to kitty.conf
As an example for what users have done, this is Yuri Khan’s scrolling extension that allows kitty scroll bindings to work in full screen applications:
import kitty.conf.utils as ku
import kitty.key_encoding as ke
from kitty import keys
import kitty.fast_data_types as fdt
def main():
pass
def actions(extended):
yield keys.defines.GLFW_PRESS
if extended:
yield keys.defines.GLFW_RELEASE
def mods_to_glfw(mods):
return sum(glfw
for mod, glfw in {ke.SHIFT: fdt.GLFW_MOD_SHIFT,
ke.CTRL: fdt.GLFW_MOD_CONTROL,
ke.ALT: fdt.GLFW_MOD_ALT,
ke.SUPER: fdt.GLFW_MOD_SUPER}.items()
if mods & mod)
def handle_result(args, result, target_window_id, boss):
w = boss.window_id_map.get(target_window_id)
if w is None:
return
if w.screen.is_main_linebuf():
getattr(w, args[1])()
return
mods, key, is_text = ku.parse_kittens_shortcut(args[2])
if is_text:
w.send_text(key)
return
extended = w.screen.extended_keyboard
for action in actions(extended):
sequence = (
('\x1b_{}\x1b\\' if extended else '{}')
.format(
keys.key_to_bytes(
getattr(keys.defines, 'GLFW_KEY_{}'.format(key)),
w.screen.cursor_key_mode, extended,
mods_to_glfw(mods), action)
.decode('ascii')))
w.write_to_child(sequence)
handle_result.no_ui = True
Hyperlinks
Kitty has full support for hyperlinks. Terminals programs generate them and kitty lets you customize the actions taken when clicking on these links. Users define custom actions in the open-actions.conf file. You can read the open actions documentation here.
For basic URLs, run ctrl-shift-e to hint all urls. When you click the hint key next to the URL you want, kitty will open the link in your browser of choice. The user can set this parameter in their kitty.conf file
with the open_url_with
option.
Scrollback
Kitty can open the scrollback in a given window by running the command ctrl-shift-h. By default, it opens with the less
pager. We can pipe the scrollback output to a separate window with any command we want too!
For example, we can open the scrollback in a window in the overlay layout running vim.
Granular Font Controls
Kitty has highly configurable font management. Beyond setting font size, font family, and what font faces to use for italic and bold text, kitty lets users configure what fonts to use for particular characters. You
can specify characters to a particular font using the symbol_map
option in the kitty.conf file. The syntax looks like this:
symbol_map codepoints Font Family Name
When specifying multiple unicode characters, separate them with commas. Finally, through the font_features
option, users can choose what OpenType features they want to enable and disable. The Harbuzz documents
detail a full list of all the options you can pass.
Configuration
Kitty, unlike some terminals, doesn’t rely on the Xresources file. Instead, the location of the configuration is ~/.config/kitty/kitty.conf on UNIX-like platforms. As an example, here’s my kitty configuration:
####### kitty.conf #######
# Fonts
font_family Source Code Pro
bold_font Source Code Pro Bold
italic_font Source Code Pro Italic
bold_italic_font Source Code Pro Bold Italic
# Size
font_size 11.0
# Scrollback
scrollback_lines 2000
map ctrl+shift+h show_scrollback
map f1 launch --stdin-source=@screen_scrollback --stdin-add-formatting less +G -R # Spawns scrollback in a new window with less
# URLs
url_color #34CCFF
url_style curly
url_prefixes http https ftp
open_url_with lynx
# Clipboard
copy_on_select no
strip_trailing_spaces smart
map ctrl+shift+c copy_to_clipboard
map ctrl+shift+v paste_from_clipboard
# Graphics
sync_to_monitor yes
# Bell
enable_audio_bell yes
bell_on_tab yes
window_alert_on_bell yes
# Appearance
background_opacity 0.95
## Color Scheme
background #111314
foreground #B7BBB7
### Black
color0 #2C2F33
color8 #4B5056
### Red
color1 #B04C50
color9 #B04C50
### Green
color2 #919652
color10 #94985B
### Yellow
color3 #E2995C
color11 #E2995C
### Blue
color4 #66899D
color12 #66899D
### Magenta
color5 #8D6494
color13 #8D6494
### Cyan
color6 #527C77
color14 #527C77
### White
color7 #606360
color15 #DDE3DC
## Window colors
active_border_color #4F7942
inactive_border_color #45514a
# Multiplexing
## Modifier
kitty_mod ctrl+alt
## Tabs
map shift+down new_tab
map ctrl+shift+q close_tab
map shift+right next_tab
map shift+left previous_tab
map ctrl+shift+right move_tab_forward
map ctrl+shift+left move_tab_backward
### Tab appearance
tab_title_template "{index}: {title}"
tab_bar_style powerline
tab_powerline_style round
active_tab_foreground #1e261d
active_tab_background #adffac
inactive_tab_foreground #202a20
inactive_tabe_background #6a786a
## Windows
map kitty_mod+enter new_window
map kitty_mod+q close_window
map kitty_mod+Right next_window
map kitty_mod+Left previous_window
Getting Kitty
Kitty is available in the package managers of most Linux distributions as well as all three major BSDs. Binary downloads are available here for Mac OS and Linux if you want the newest version and your OS doesn’t have it.