repos / dotfiles

my dotfiles

dotfiles / dot_config / kak
Eric Bower  ·  2026-04-13

kakrc

  1colorscheme gruvbox-dark
  2
  3face global Information default,rgb:504945
  4face global PrimarySelection default,rgb:458588
  5set-option global autoreload true
  6set-option global grepcmd 'rg -n'
  7set-option global ui_options terminal_assistant=none # disable clippy
  8set-option global scrolloff 3,3
  9
 10hook global BufOpenFile .* editorconfig-load
 11hook global BufNewFile .* editorconfig-load
 12hook global WinCreate .* %{
 13	addhl window/ column 80 default,rgb:404040
 14	addhl window/ column 100 default,rgb:404040
 15}
 16add-highlighter global/ show-matching
 17
 18map global user y ":copy-to-osc<ret>"						-docstring "copy selection to OSC52 clipboard"
 19map global user u ":copy-github-permalink<ret>" -docstring "copy github permalink"
 20map global user t ":copy-filename-to-osc<ret>"	-docstring "copy filename to OSC52 clipboard"
 21map global user f ":find<space>"								-docstring "find file"
 22map global user g ":grep<space>"								-docstring "grep project directory"
 23map global user q ":delete-buffer<ret>"					-docstring "close buffer"
 24map global user b ":buffer<space>"							-docstring "buffer list"
 25map global user B ":delete-buffer-picker<ret>"	-docstring "delete buffer"
 26
 27define-command find -docstring "find files" -params 1 %{ edit %arg{1} }
 28complete-command find shell-script-candidates %{ fd -t f }
 29
 30define-command dowrap %{ # soft-wrap command
 31	add-highlighter buffer/ wrap -indent -word -marker ""
 32	map buffer normal j gd
 33	map buffer normal k gu
 34}
 35
 36define-command copy-to-osc %{
 37	nop %sh{
 38		encoded=$(printf %s "$kak_selections" | base64 | tr -d '\n')
 39		printf "\e]52;;%s\e\\" "$encoded" >/dev/tty
 40	}
 41	echo "Copied selections to OSC52 clipboard"
 42}
 43
 44define-command copy-filename-to-osc %{
 45	nop %sh{
 46    encoded=$(printf "%s" "$kak_buffile" | sed "s|^$(pwd)/||" | base64 | tr -d '\n')
 47		printf "\e]52;;%s\e\\" "$encoded" >/dev/tty
 48	}
 49	echo "Copied filename to OSC52 clipboard"
 50}
 51
 52define-command copy-github-permalink %{
 53    evaluate-commands %sh{
 54        file=$(printf "%s" "$kak_buffile" | sed "s|^$(pwd)/||")
 55        line="$kak_cursor_line"
 56        github_remote=$(git config --get-regexp '^remote\..*\.url' | grep github.com | head -1 | awk '{print $2}')
 57        if [[ -z "$github_remote" ]]; then
 58            printf "echo 'error: No github remote found'"
 59        else
 60            remote=$(echo "$github_remote" | sed 's|^.*://||;s|^git@||;s|:|/|;s|\.git$||')
 61            commit=$(git rev-parse HEAD)
 62            url="https://$remote/blob/$commit/$file#L$line"
 63            encoded=$(printf %s "$url" | base64 | tr -d '\n')
 64            printf "set-register '\"' '%s'\n" "$url"
 65            printf "nop %%sh{ printf '\\e]52;;%s\\e\\\\' '%s' >/dev/tty }\n" "$encoded"
 66            printf "echo 'Copied github permalink to clipboard'"
 67        fi
 68    }
 69}
 70
 71define-command delete-buffer-picker %{
 72	prompt -menu -buffer-completion 'delete buffer:' %{
 73		delete-buffer %val{text}
 74	}
 75}
 76
 77evaluate-commands %sh{
 78    if command -V kak-lsp >/dev/null 2>/dev/null ; then
 79        kak-lsp --kakoune -s $kak_session
 80        echo "
 81            set-option global modelinefmt \"%opt{lsp_modeline} %opt{modelinefmt}\"
 82            map global user <l> %{: enter-user-mode lsp<ret>} -docstring 'LSP commands'
 83            map global insert <tab> '<a-;>:try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks <lt>tab> }<ret>' -docstring 'Select next snippet placeholder'
 84            map global object d '<a-semicolon>lsp-diagnostic-object error warning<ret>' -docstring 'LSP errors and warnings'
 85            map global object D '<a-semicolon>lsp-diagnostic-object error<ret>' -docstring 'LSP errors'
 86
 87            hook global BufSetOption filetype=python %{
 88                set-option buffer lsp_servers %{
 89                    [pyright]
 90                    command = 'pyright-langserver'
 91                    args = ['--stdio']
 92                    root_globs = ['pyrightconfig.json', 'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'Pipfile', '.git']
 93                }
 94                lsp-enable-window
 95            }
 96            hook global WinSetOption filetype=(python|go|javascript|typescript|zig) %{
 97            	lsp-enable-window
 98            }
 99        "
100    else
101        echo "echo -debug kak-lsp not found in PATH"
102    fi
103}