Kakoune offers already various integrations for external tools such as git, ranger and various others. Recently there was also some nice integration of fzf made public (although afaik not (yet) included in the kakoune distribution).

I took all this, put it in my config, modified it to my needs and extended it a little.

images/screenshots/kakoune_external_thumb.png

The result is a configuration with the following features:

  • A keybinding to change working directory to that of currently open file.
  • Run external commands (like ranger, fzf, shell) from kakoune to open files. If kakoune is running inside a tmux, create a split for the external command, otherwise spawn a new urxvt instance (useful esp. with a tiling window manager).
  • Ranger and/or FZF can be used this way to select files to open, either in the "main window" or in the one they are running.
  • Fzf can select from files in current subdirectory or from surrounding git project (using git ls-tree).
  • The users default $SHELL can be spawned this way. Optionally a single shell command can be run.
  • Automatically cd into the directory of the current file before executing an external command (no need for autochdir)
Keybinding Command Description
,c :cd-to-buffer Change kakoune's working directory to that of currently open file
,wk, ,Wk :run-kakoune Create a new window (tmux pane or urxvt instance) with a kakoune connected to the same session
,wr :open-ranger Create a new window (tmux pane or urxvt instance) with ranger as a file chooser for the original window (ranger window will disappear when file is selected)
,wR, ,WR :run-ranger Create a new window (tmux pane or urxvt instance) with an independent ranger instance
,wf :open-fzf-file Create a new window (tmux pane or urxvt instance) with fzf as a file chooser (all files below current dir) for the original window (fzf window will disappear when file is selected)
,wg :open-fzf-git Create a new window (tmux pane or urxvt instance) with fzf as a file chooser (all files tracked by git) for the original window (fzf window will disappear when file is selected)
,ws, ,WS :run-shell Create a new window (tmux pane or urxvt instance) with $SHELL
,Wr :new-open-ranger Create a new window (tmux pane or urxvt instance) with ranger as a file chooser for the now window (ranger window will be replaced with kakoune)
,Wf :new-open-fzf-file Create a new window (tmux pane or urxvt instance) with fzf as a file chooser (all files below current dir) for the original window (fzf window will be replaced with kakoune)
,Wg :new-open-fzf-git Create a new window (tmux pane or urxvt instance) with fzf as a file chooser (all files tracked by git) for the original window (fzf window will be replaced with kakoune)
<TAB> (Insert mode) Indent current line by one level using either spaces or tabs (according to indentwidth)
S-<TAB> (Insert mode) De-Indent current line by one level using either spaces or tabs (according to indentwidth)
:run-shell [cmd] Create a new window (tmux pane or urxvt instance) running the command [rev] under /bin/sh, waiting for keypress afterwards.
:run-git-show [rev] Create a new window (tmux pane or urxvt instance) with a read-only kak showing the current file as of revision [rev] (defaults to HEAD)

The config files behind this magic can be found in my public-dotfiles repo.