{ pkgs, ... }: {
  enable = true;
  defaultEditor = true;
  # plugins = with pkgs; [ kakounePlugins.kak-fzf ];
  config = {
    colorScheme = "tomorrow-night";
    numberLines = {
      enable = true;
      highlightCursor = true;
    };
    indentWidth = 2;
    hooks = [
        {
          # When the filetype=latex option is set in a buffer context (automatically), add a new hook to build the latex file on write
          name = "BufSetOption";
          option = "filetype=latex";
          commands = "hook buffer BufWritePost .* %{ texlab-build }";
        }
        {
          # When the filetype=markdown option is set (automatically), set word wrap on
          name = "BufSetOption";
          option = "filetype=markdown";
          commands = "add-highlighter buffer wrap -word";
        }
    ];
    keyMappings = [
      # Define select all
      {
        key = "a";
        mode = "user";
        effect = "*%s<ret>";
        docstring = "Select all";
      }
      # Define usermode yank/copy and paste
      {
        key = "y";
        mode = "user";
        effect = "<a-|> wl-copy<ret>";
      }
      {
        key = "p";
        mode = "user";
        effect = "<a-!> wl-paste<ret>;d"; # ;d at the end since newline inserted
      }
      {
        key = "P";
        mode = "user";
        effect = "! wl-paste<ret>;d"; # ;d at the end since newline inserted
      }
    ];
  };
  extraConfig = ''
    # highlight trailing whitespace
    add-highlighter global/trailing-whitespace regex '\h+$' 0:Error

    # don't remove trailing indent
    set global disabled_hooks .*-trim-indent
    source ${pkgs.writeText "kakoune-divider.kak" (builtins.readFile ./kakoune/divider.kak)}
    set-option global divider_face LineNumbers
    divider-on 80

    eval %sh{kak-lsp --kakoune -s $kak_session}
    lsp-enable
  '';
}
