main dotfiles / dot_config / kak / kakrc
Eric Bower  ·  2026-10-14
  1colorscheme default
  2
  3face global Information      default,black
  4face global PrimarySelection black,blue
  5face global MenuBackground   default,default@Information
  6face global MenuForeground   default,default@PrimarySelection
  7face global MenuInfo         default,default@Information
  8face global MatchingChar     black,blue
  9face global Whitespace       bright-black,default
 10
 11set-option global autoreload true
 12set-option global grepcmd 'rg -n'
 13set-option global ui_options terminal_assistant=none # disable clippy
 14set-option global scrolloff 3,3
 15
 16hook global BufOpenFile .* %{ modeline-parse }
 17hook global BufOpenFile .* editorconfig-load
 18hook global BufNewFile .* editorconfig-load
 19hook global WinCreate .* %{
 20    addhl window/ column 80 default,bright-black
 21    addhl window/ column 100 default,bright-black
 22}
 23add-highlighter global/ show-matching
 24add-highlighter global/highlight-todos regex \b(TODO|NOTE)\b 0:+rb
 25
 26map global user y ":copy-to-osc<ret>"           -docstring "copy selection to OSC52 clipboard"
 27map global user u ":copy-github-permalink<ret>" -docstring "copy github permalink"
 28map global user t ":copy-filename-to-osc<ret>"  -docstring "copy filename to OSC52 clipboard"
 29map global user f ":find<space>"                -docstring "find file"
 30map global user g ":grep<space>"                -docstring "grep project directory"
 31map global user G '<a-i>w:grep "\b<c-r>.\b"<ret>' -docstring "grep word under cursor"
 32map global user * '<a-i>w:grep "\b<c-r>.\b"<ret>' -docstring "grep word under cursor"
 33map global user q ":delete-buffer<ret>"         -docstring "close buffer"
 34map global user b ":buffer<space>"              -docstring "buffer list"
 35map global user B ":delete-buffer-picker<ret>"  -docstring "delete buffer"
 36
 37define-command find -docstring "find files" -params 1 %{ edit %arg{1} }
 38complete-command find shell-script-candidates %{ fd -t f }
 39
 40define-command dowrap %{ # soft-wrap command
 41    add-highlighter buffer/ wrap -indent -word -marker "… "
 42    map buffer normal j gd
 43    map buffer normal k gu
 44}
 45
 46define-command dowhite %{
 47    add-highlighter buffer/ show-whitespaces
 48}
 49
 50define-command nowhite %{
 51    remove-highlighter buffer/show-whitespaces
 52}
 53
 54define-command copy-to-osc %{
 55    nop %sh{
 56        encoded=$(printf %s "$kak_selections" | base64 | tr -d '\n')
 57        printf "\e]52;;%s\e\\" "$encoded" >/dev/tty
 58    }
 59    echo "Copied selections to OSC52 clipboard"
 60}
 61
 62define-command copy-filename-to-osc %{
 63    nop %sh{
 64        encoded=$(printf "%s" "$kak_buffile" | sed "s|^$(pwd)/||" | base64 | tr -d '\n')
 65        printf "\e]52;;%s\e\\" "$encoded" >/dev/tty
 66    }
 67    echo "Copied filename to OSC52 clipboard"
 68}
 69
 70define-command copy-github-permalink %{
 71    evaluate-commands %sh{
 72        file=$(printf "%s" "$kak_buffile" | sed "s|^$(pwd)/||")
 73        line="$kak_cursor_line"
 74        github_remote=$(git config --get-regexp '^remote\..*\.url' | grep github.com | head -1 | awk '{print $2}')
 75        if [[ -z "$github_remote" ]]; then
 76            printf "echo 'error: No github remote found'"
 77        else
 78            remote=$(echo "$github_remote" | sed 's|^.*://||;s|^git@||;s|:|/|;s|\.git$||')
 79            commit=$(git rev-parse HEAD)
 80            url="https://$remote/blob/$commit/$file#L$line"
 81            encoded=$(printf %s "$url" | base64 | tr -d '\n')
 82            printf "set-register '\"' '%s'\n" "$url"
 83            printf "nop %%sh{ printf '\\e]52;;%s\\e\\\\' '%s' >/dev/tty }\n" "$encoded"
 84            printf "echo 'Copied github permalink to clipboard'"
 85        fi
 86    }
 87}
 88
 89define-command delete-buffer-picker %{
 90    prompt -menu -buffer-completion 'delete buffer:' %{
 91        delete-buffer %val{text}
 92    }
 93}
 94
 95set-option global ctagscmd 'ctags-project'
 96set-option global ctagsfiles 'tags' 'tags_deps'
 97map global user d       '<a-i>w: ctags-search<ret>' -docstring 'ctags jump to definition'
 98map global user D       ': ctags-generate<ret>'     -docstring 'generate tags file'
 99map global user s       ': ctags-file-symbols<ret>' -docstring 'search symbols in current file'
100
101define-command ctags-deps -docstring "Generate tags_deps for third-party dependencies" %{
102    echo -markup "{Information}generating dependency tags in background..."
103    nop %sh{ (
104        trap - INT QUIT
105        while ! mkdir tags_deps.kaklock 2>/dev/null; do sleep 1; done
106        trap 'rmdir tags_deps.kaklock' EXIT
107
108        if ctags-deps; then
109            msg="dependency tags generated"
110        else
111            msg="failed to generate dependency tags"
112        fi
113        printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}${msg}'" | kak -p ${kak_session}
114    ) >/dev/null 2>&1 </dev/null & }
115}
116
117define-command ctags-file-symbols -docstring "Browse and jump to functions in current file" %{
118    require-module menu
119    evaluate-commands %sh{
120        ctags-file-symbols "$kak_buffile"
121    }
122}
123
124hook global WinCreate .* %{
125    ctags-enable-autoinfo
126}
127hook global InsertCompletionShow .* %{
128    try %{ ctags-complete }
129}
130hook global BufWritePost .* %{
131    ctags-update-tags
132}
133
134hook global WinSetOption filetype=zig %{
135    evaluate-commands %sh{
136        cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
137        printf 'set-option window ctagsfiles "tags" "tags_deps" "%s/tags/zig_std.tags"\n' "$cache_dir"
138    }
139}
140
141hook global WinSetOption filetype=go %{
142    evaluate-commands %sh{
143        cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
144        printf 'set-option window ctagsfiles "tags" "tags_deps" "%s/tags/go_std.tags"\n' "$cache_dir"
145    }
146}
147
148hook global WinSetOption filetype=python %{
149    evaluate-commands %sh{
150        cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
151        printf 'set-option window ctagsfiles "tags" "tags_deps" "%s/tags/python_std.tags"\n' "$cache_dir"
152    }
153}
154
155hook global WinSetOption filetype=(javascript|typescript) %{
156    evaluate-commands %sh{
157        cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
158        printf 'set-option window ctagsfiles "tags" "tags_deps" "%s/tags/ts_std.tags"\n' "$cache_dir"
159    }
160}
161
162