Connect.kak: Built in integrations, framework and workflow

connect.kak is a great plugin developed by @alexherbo2 that has been around for some time.

The plugin has changed a lot in the lasts months, partly because it tries to solve new problems. It was necessary to improve the documentation to explain its power. You can check the changes in the repository.

In this post I will try to summarize the features connect.kak provides.



The objective of connect.kak is to synchronize external applications with Kakoune clients easily. A typical use case is opening a file browser and having it open the files in the Kakoune client. Another very typical use case is connecting a terminal.

connect.kak provides basic commands to interact with the connected client interactively or to write your own scripts (check :batch , which is an integration crafted from the rest of the commands) as well as a set of officially supported modules (Kakoune commands to programs).

As stated, connect.kak is about linking or mutually controlling other programs and Kakoune clients (or sessions, actually). However, it’s more than that. connet.kak provides three different things: built in integrations (which can be used out of the box), a framework for developing for kakoune outside kakoune and extensions to your workflow. I will cover the three in the next posts.

Built in Integrations

connect.kak provides a set of sub-modules and commands that are of enough value by themselves. As of today, it comes with the following integration of common apps:

And lots of applications don’t need anything special to work and can be spawned with connect-terminal (>) or connect-shell ($).

In addition, it allows you to connect your shell, which is very handy to edit new files, compile the current buffer, or similar actions.

If you want some of this features, connect.kak already provides a lot of value.

connect.kak as a framework


You can also define your own connect commands and aliases and locate them in a path set in the connect_paths option. By default, it is set to your $XDG_CONFIG_HOME/kak/connect/commands and $XDG_CONFIG_HOME/kak/connect/aliases folders.

connect.kak is extensible. It provides a set of basic commands that allow you to write scripts to interact with Kakoune saving a lot of effort.

Your own plugins can register commands and use connect.kak basic utilities if they interact with other applications. This is the reason connect.kak can act as a base framework.

connect.kak also provides a .desktop entry to integrate Kakoune in your linux desktop (GNOME, KDE, etc).

Right now, there are two more plugins developed by @alexherbo2 that can optionally integrate with connect.kak: yank-ring.kak and batch.kak.

Extending your workflow


connect.kak can improve your current workflow too.

For example, Kakoune can be suspended using <c-z> to recover your terminal and execute other programs. With connect.kak, a typical workflow is working with a connected shell (started with kak-shell or by detaching from a current session with connect-detach (&) ). If you map quit, you can easily detach and reattach (closing the current client), but also reattach from a different shell, reattach opening new files, reattach from a terminal file manager, etc. With barebones Kakoune you can also start a file manager and edit files with Kakoune, but then you enforce the stack shell → file manager -> kakoune, and you also need to start the applications in that order. connect.kak makes that workflow simpler: switch applications however you like, launch application when you need them, control Kakoune where you need it.

kak-shell :attach lets your run a client connected to a session, just like kak -c <session id> . But with kak-shell :attach you have a list of all the active sessions and you can also create a new named session which starts in headless mode, which is very useful for detaching and reattaching continually.

Therefore, kak-shell :attach replaces kak -c <session id> and kak -d -s <session id> and can serve to spawn a client in whatever situation you are.

Tip : You can alias kak-shell to something like ks , and you’d only need to type ks :a .


A good alias for kak or :a.


# Attach fall-back "kak-shell :attach" + optional connect

if [ "$IN_KAKOUNE_CONNECT" ]; then
    :attach "$@"
    # Get a value from a client (source: :get)
    mkfifo connect.fifo
    trap 'rm connect.fifo' EXIT
    kak-shell ":send echo -to-file \"$PWD/connect.fifo\" %val{session}" || exit $?
    SESSION="$(cat connect.fifo)"
    kak -c "$SESSION" "$@"

    printf "Do you want to connect to the previous session ($SESSION)? [Y]es/[N]o :"
    read key
    [ "$key" = "n" -o "$key" = "N" ] && exit 0

	kak -c "$SESSION" -e "connect-detach"

One of my most beloved command currently is:

rails routes | :fifo

You have all the comfy of your shell/terminal and can forward to clients command outputs.


And a lot more of application don’t need anything special to work and can be spawned with connect-terminal (>) or connect-shell ($).

It is true. :o

One goal of connect.kak is to provide seamless integrations. For example, lf integration is just that:


define-command lf -params .. -file-completion -docstring 'Open files with lf' %{
  > lf %arg{@}

It just provides the nicety to have a lf command from Kakoune.