main dotfiles / dot_config / kak / kakrc
Eric Bower  ·  2026-09-08
  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 q ":delete-buffer<ret>"         -docstring "close buffer"
 32map global user b ":buffer<space>"              -docstring "buffer list"
 33map global user B ":delete-buffer-picker<ret>"  -docstring "delete buffer"
 34
 35define-command find -docstring "find files" -params 1 %{ edit %arg{1} }
 36complete-command find shell-script-candidates %{ fd -t f }
 37
 38define-command dowrap %{ # soft-wrap command
 39    add-highlighter buffer/ wrap -indent -word -marker ""
 40    map buffer normal j gd
 41    map buffer normal k gu
 42}
 43
 44define-command dowhite %{
 45    add-highlighter buffer/ show-whitespaces
 46}
 47
 48define-command nowhite %{
 49    remove-highlighter buffer/show-whitespaces
 50}
 51
 52define-command copy-to-osc %{
 53    nop %sh{
 54        encoded=$(printf %s "$kak_selections" | base64 | tr -d '\n')
 55        printf "\e]52;;%s\e\\" "$encoded" >/dev/tty
 56    }
 57    echo "Copied selections to OSC52 clipboard"
 58}
 59
 60define-command copy-filename-to-osc %{
 61    nop %sh{
 62        encoded=$(printf "%s" "$kak_buffile" | sed "s|^$(pwd)/||" | base64 | tr -d '\n')
 63        printf "\e]52;;%s\e\\" "$encoded" >/dev/tty
 64    }
 65    echo "Copied filename to OSC52 clipboard"
 66}
 67
 68define-command copy-github-permalink %{
 69    evaluate-commands %sh{
 70        file=$(printf "%s" "$kak_buffile" | sed "s|^$(pwd)/||")
 71        line="$kak_cursor_line"
 72        github_remote=$(git config --get-regexp '^remote\..*\.url' | grep github.com | head -1 | awk '{print $2}')
 73        if [[ -z "$github_remote" ]]; then
 74            printf "echo 'error: No github remote found'"
 75        else
 76            remote=$(echo "$github_remote" | sed 's|^.*://||;s|^git@||;s|:|/|;s|\.git$||')
 77            commit=$(git rev-parse HEAD)
 78            url="https://$remote/blob/$commit/$file#L$line"
 79            encoded=$(printf %s "$url" | base64 | tr -d '\n')
 80            printf "set-register '\"' '%s'\n" "$url"
 81            printf "nop %%sh{ printf '\\e]52;;%s\\e\\\\' '%s' >/dev/tty }\n" "$encoded"
 82            printf "echo 'Copied github permalink to clipboard'"
 83        fi
 84    }
 85}
 86
 87define-command delete-buffer-picker %{
 88    prompt -menu -buffer-completion 'delete buffer:' %{
 89        delete-buffer %val{text}
 90    }
 91}
 92
 93# evaluate-commands %sh{
 94#     if command -V kak-lsp >/dev/null 2>/dev/null ; then
 95#         kak-lsp --kakoune -s $kak_session
 96#         echo "
 97#             set-option global modelinefmt \"%opt{lsp_modeline} %opt{modelinefmt}\"
 98#             map global user <l> %{: enter-user-mode lsp<ret>} -docstring 'LSP commands'
 99#             map global insert <tab> '<a-;>:try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks <lt>tab> }<ret>' -docstring 'Select next snippet placeholder'
100#             map global object d '<a-semicolon>lsp-diagnostic-object error warning<ret>' -docstring 'LSP errors and warnings'
101#             map global object D '<a-semicolon>lsp-diagnostic-object error<ret>' -docstring 'LSP errors'
102# 
103#             hook global BufSetOption filetype=python %{
104#                 set-option buffer lsp_servers %{
105#                     [pyright]
106#                     command = 'pyright-langserver'
107#                     args = ['--stdio']
108#                     root_globs = ['pyrightconfig.json', 'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'Pipfile', '.git']
109#                 }
110#                 lsp-enable-window
111#             }
112#             hook global WinSetOption filetype=(python|go|javascript|typescript|zig) %{
113#             	lsp-enable-window
114#             }
115#         "
116#     else
117#         echo "echo -debug kak-lsp not found in PATH"
118#     fi
119# }
120
121set-option global ctagsfiles 'tags' '.tags_deps'
122map global user d       '<a-i>w: ctags-search<ret>' -docstring 'ctags jump to definition'
123map global user D       ': ctags-generate<ret>'     -docstring 'generate tags file'
124map global user s       ': ctags-file-symbols<ret>' -docstring 'search symbols in current file'
125
126define-command ctags-generate-deps -docstring "Generate .tags_deps for third-party dependencies" %{
127    echo -markup "{Information}generating dependency tags in background..."
128    nop %sh{ (
129        if gen-deps-tags; then
130            msg="dependency tags generated"
131        else
132            msg="failed to generate dependency tags"
133        fi
134        printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}${msg}'" | kak -p ${kak_session}
135    ) >/dev/null 2>&1 </dev/null & }
136}
137
138define-command ctags-file-symbols -docstring "Browse and jump to functions in current file" %{
139    require-module menu
140    evaluate-commands %sh{
141        kak-file-symbols "$kak_buffile"
142    }
143}
144
145hook global WinCreate .* %{
146    ctags-enable-autoinfo
147}
148hook global InsertCompletionShow .* %{
149    try %{ ctags-complete }
150}
151hook global BufWritePost .* %{
152    ctags-update-tags
153}
154
155hook global WinSetOption filetype=zig %{
156    evaluate-commands %sh{
157        cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
158        printf 'set-option window ctagsfiles "tags" ".tags_deps" "%s/tags/zig_std.tags"\n' "$cache_dir"
159    }
160}
161
162hook global WinSetOption filetype=go %{
163    evaluate-commands %sh{
164        cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
165        printf 'set-option window ctagsfiles "tags" ".tags_deps" "%s/tags/go_std.tags"\n' "$cache_dir"
166    }
167}
168
169hook global WinSetOption filetype=python %{
170    evaluate-commands %sh{
171        cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
172        printf 'set-option window ctagsfiles "tags" ".tags_deps" "%s/tags/python_std.tags"\n' "$cache_dir"
173    }
174}
175
176hook global WinSetOption filetype=(javascript|typescript) %{
177    evaluate-commands %sh{
178        cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
179        printf 'set-option window ctagsfiles "tags" ".tags_deps" "%s/tags/ts_std.tags"\n' "$cache_dir"
180    }
181}
182
183