My configurations for the software I use
1# Load Plugin Manager
2source "%val{config}/plugins/plug.kak/rc/plug.kak"
3
4# Plugins
5plug "whereswaldon/shellcheck.kak"
6
7# Custom Filetypes
8hook global BufCreate .*[.](roc) %{
9 set-option buffer filetype roc
10}
11
12# kak-lsp
13eval %sh{ kak-lsp }
14
15hook global WinSetOption filetype=(c|cpp|erlang|go|java|javascript|nix|python|roc|typst|zig) %{
16 lsp-enable-window
17
18 map global user l ':enter-user-mode lsp<ret>' -docstring 'Enter kak-lsp mode'
19 map global insert -docstring %{
20 Select next snippet placeholder
21 } <c-space> '<a-semicolon>:lsp-snippets-select-next-placeholders<ret>'
22 map global object a '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
23 map global object <a-a> '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
24 map global object f '<a-semicolon>lsp-object Function Method<ret>' -docstring 'LSP function or method'
25 map global object t '<a-semicolon>lsp-object Class Interface Struct<ret>' -docstring 'LSP class interface/struct'
26 map global object d '<a-semicolon>lsp-diagnostic-object --include-warnings<ret>' -docstring 'LSP errors & warnings'
27 map global object D '<a-semicolon>lsp-diagnostic-object<ret>' -docstring 'LSP errors'
28
29 lsp-inlay-hints-enable window
30 lsp-inlay-diagnostics-enable window
31}
32
33hook -group lsp-filetype-nix global BufSetOption filetype=nix %{
34 set-option buffer lsp_servers %{
35 [nixd]
36 root_globs = [ "flake.nix", "shell.nix", ".git", ".hg" ]
37 }
38}
39
40hook -group lsp-filetype-python global BufSetOption filetype=python %{
41 set-option buffer lsp_servers %{
42 [ruff]
43 args = [ "server", "--quiet" ]
44 root_globs = [ "requirements.txt", "setup.py", "pyproject.toml", "uv.lock", ".git" ]
45 settings_section = "_"
46 # [ruff.settings._.globalSettings]
47 [ty]
48 args = [ "server" ]
49 root_globs = [ "requirements.txt", "setup.py", "pyproject.toml", "uv.lock", ".git" ]
50 }
51}
52
53hook -group lsp-filetype-typst global BufSetOption filetype=typst %{
54 set-option buffer lsp_servers %{
55 [tinymist]
56 root_globs = [ ".git" ]
57 settings_section = "tinymist"
58 [tinymist.settings.tinymist]
59 outputPath = "$root/_preview/$dir/$name"
60 fontPaths = [ "./assets/fonts" ]
61 formatterMode = "typstyle"
62 typstExtraArgs = [ "--features=html" ]
63 }
64}
65
66hook -group lsp-filetype-roc global BufSetOption filetype=roc %{
67 set-option buffer lsp_servers %{
68 [roc_language_server]
69 root_globs = [ ".git" ]
70 }
71}
72
73hook -group lsp global WinSetOption filetype=go %{
74 hook -group lsp-format buffer BufWritePost .* %{
75 evaluate-commands %sh{
76 goimports -e -w "$kak_buffile"
77 }
78 edit!
79 }
80}
81
82# Column Indicator
83define-command -params 2..3 -docstring \
84"Add or remove column indicators. Takes three arguments: <add|remove> <column_number> <color>
85Where color is in the format <foreground>[,background][+attribute]." \
86m-columnindicator %{
87 evaluate-commands %sh{
88 [ "$1" = add ] && {
89 [ "$3" ] && color=$3 || color=default,bright-white
90 printf '%s\n' "eval addhl window/ column $(($2 + 1)) $color"
91 }
92
93 [ "$1" = remove ] && {
94 [ "$3" ] && color=$3 || color=default,bright-white
95 printf '%s\n' "eval rmhl window/column_$(($2 + 1))_$color"
96 }
97 }
98}
99
100# Template Command
101define-command -params 1 -docstring \
102"Print template into the current file. Templates are located at %val{config}/templates." \
103m-template %{
104 evaluate-commands %sh{
105 [ -e "$kak_config/templates/$1" ] \
106 && printf '%s\n' "exec !cat<space>$kak_config/templates/$1<ret>" \
107 || printf '%s\n' "echo Template $1 doesn't exist."
108 }
109} -shell-script-candidates %{ cd "$kak_config/templates"; printf '%s\n' * }
110
111# Whitespace command
112define-command -params 2 -docstring \
113"Set whitespace options. Takes two arguments: <tabs|spaces> <size>" \
114m-whitespace %{
115 evaluate-commands %sh{
116 [ "$1" = tabs ] \
117 && printf '%s\n' \
118 "eval set window indentwidth 0" \
119 "eval set window tabstop $2" \
120 "eval map window insert <tab> <tab>"
121
122 [ "$1" = spaces ] && {
123 s=0
124 while [ "$s" -lt "$2" ]
125 do
126 size="$size\ "
127 s=$((s+1))
128 done
129
130 printf '%s\n' \
131 "eval set window indentwidth $2" \
132 "eval map window insert <tab> \"$size\""
133 }
134 }
135}
136
137# Keybinds
138## User
139map global user c ':comment-line<ret>' -docstring 'comment line'
140map global user C ':comment-block<ret>' -docstring 'comment block'
141map global user f ':try format catch lsp-formatting<ret>' -docstring 'Run formatcmd or lsp formatter'
142map global user p '!wl-paste<ret>' -docstring 'Paste from System Clipboard (Wayland)'
143map global user y '<a-|>wl-copy<ret>' -docstring 'Copy to System Clipboard (Wayland)'
144map global user . ':source ".kakrc.local"<ret>' -docstring 'Load the kakrc file in the current directory'
145
146# Set termcmd
147hook global ModuleLoaded wayland %{
148 set-option global termcmd "foot sh -c"
149}
150
151# Enable Wrapping
152add-highlighter global/ wrap -indent
153
154# Highlight Matching Characters
155add-highlighter global/ show-matching
156
157# Highlight TODO and friends
158add-highlighter global/ regex \b(TODO|FIXME)\b 0:default+rb
159
160# Show Trailing Whitespace
161add-highlighter global/ show-whitespaces -lf ' ' -indent '' -spc '█' -only-trailing
162
163# Set theme_type
164evaluate-commands %sh{
165 [ "$TERM" = linux ] && {
166 printf '%s\n' "decl str theme_type none"
167 return 0
168 }
169 . $(cat "${XDG_STATE_HOME:-$HOME/.local/state}/thm/current_thm")
170 case $theme_type in
171 light ) printf '%s\n' "decl str theme_type light" ;;
172 dark ) printf '%s\n' "decl str theme_type dark" ;;
173 * ) return 0 ;;
174 esac
175}
176
177hook global WinCreate .* %{
178 # Add column indicator at column 101
179 m-columnindicator add 120
180
181 # Indentation Options
182 set-option window indentwidth 0
183 set-option window tabstop 4
184}
185
186# Filetype specific options
187hook global WinSetOption filetype=(css|html|java|javascript|markdown|meson|nix|typst|xml|yaml) %{
188 m-whitespace spaces 2
189}
190
191hook global WinSetOption filetype=erlang %{
192 set-option buffer formatcmd "erlfmt -"
193 m-whitespace spaces 4
194}
195
196hook global WinSetOption filetype=css %{
197 set-option buffer formatcmd "prettier --parser css"
198}
199
200hook global WinSetOption filetype=html %{
201 set-option buffer formatcmd "prettier --parser html"
202}
203
204hook global WinSetOption filetype=nix %{
205 set-option buffer formatcmd "nixfmt -w 120"
206}
207
208hook global WinSetOption filetype=java %{
209 set-option buffer formatcmd "google-java-format -"
210}
211
212hook global WinSetOption filetype=javascript %{
213 set-option buffer formatcmd "prettier --parser babel"
214}
215
216hook global WinSetOption filetype=(python|roc|zig) %{
217 m-whitespace spaces 4
218}
219
220hook global WinSetOption filetype=zig %{
221 set-option buffer formatcmd "zig fmt --stdin"
222}
223
224hook global WinSetOption filetype=git-commit %{
225 m-columnindicator remove 120
226 m-columnindicator add 70
227}
228
229hook global WinSetOption filetype=markdown %{
230 m-columnindicator remove 120
231 remove-highlighter global/wrap_-indent
232 add-highlighter global/ wrap -indent -word
233}
234
235# Status Line
236# set global modelinefmt '%val{bufname} %val{cursor_char_column},%val{cursor_line} {{context_info}} '
237# set -add global modelinefmt '{{mode_info}} - %sh{printf $USER} %sh{date +"%R %Z"} '
238#set -add global modelinefmt '%sh{cat /sys/class/power_supply/BAT0/capacity} '
239
240# Set colorscheme
241evaluate-commands %sh{
242 case "$kak_opt_theme_type" in
243 dark ) printf '%s\n' "colorscheme theme-dark" ;;
244 light ) printf '%s\n' "colorscheme theme" ;;
245 * ) printf '%s\n' "colorscheme default" ;;
246 esac
247}