Jeremy Minton About
Fixing ctrl+arrow to jump words in Alacritty terminal.
Posted by Jeremy Minton, ,

A small, but frustrating, behaviour with my default installation: within the terminal/shell “Ctrl + Left” outputs ;5D instead of jumping left to the end of the word, and equivalently with “Ctrl + Right”. My current installation is nixos with alacritty/zsh and the relevant configuration is

    programs.alacritty = {
        enable = true;
        settings = {
            font.size = 6.0;
            colors = {...};
            window.opacity = 0.9;
            key_bindings = [
                { key = "C"; mods = "Control|Shift"; action = "Copy"; }
                { key = "Insert"; mods = "Shift"; action = "PasteSelection"; }
            ];
        };
    };
    programs.zsh = {
        enable = true;
        defaultKeymap = "emacs";
        enableCompletion = true;
        shellAliases = {...};
    };

The first challenge is to understand the respective responsibilities of the shell and the terminal and which of these should be configured to solve the problem at hand. For something different, I thought I’d ask open-assistant.io.

prompt: what is the difference between a shell and a terminal

response:
A terminal provides an interface for you to interact with your operating system, such
as by running commands or viewing output.
A shell is software that manages this interaction (often referred to as "command-line
interfaces" -- CLI) in a way intended to be human friendly. While there are many
different kinds of shells available, some common examples include bash, csh/tcsh,
fish, zsh, etcetera. Different shells have varying syntaxes and capabilities, but all
perform similar functions underneath: interpreting user input and executing commands
against your operating system based on them.

This seems pretty reasonable and checks out with an explanation I recall from reading about this previously: it’s called a terminal because it used to be the keyboard and screen accessing a mainframe; and the shell is akin to a programming language for commanding the OS and other programs.

From these descriptions, I’d guess that it’s the terminal that needs to be configured.

Sure enough, a search of “ctrl+arrow in alacritty” brings up a (StackOverflow question)[https://stackoverflow.com/questions/72857879/correct-keybindings-configuration-for-zsh-in-alacritty] addressing keybindings in alacritty with zsh.

Translating the solution into nixos configuration gives a simple two lines

programs.alacritty.settings.key_bindings = [
    { key = "Left"; mods = "Control"; chars = "\\eb"; }
    { key = "Right"; mods = "Control"; chars = "\\ef"; }
];

Rebuild and voila problem solved!