2023-06-29 16:36:53 +00:00
# Enable kak-tree-sitter
2024-03-01 11:03:01 +00:00
eval %sh{ kak-tree-sitter --kakoune -d --server --with-text-objects }
map global normal <c-t> ": enter-user-mode tree-sitter<ret>"
2023-09-27 12:26:19 +00:00
## Set some color overrides
set global kts_yellow "rgb:e2b75e"
set global kts_teal "rgb:008080"
set global kts_mauve "rgb:c264ff"
set global kts_sky "rgb:6aa622"
2021-09-29 21:11:33 +00:00
# Color scheme
2023-06-29 16:36:53 +00:00
colorscheme catppuccin-latte
set global background default
2021-09-29 21:11:33 +00:00
2024-03-30 13:48:55 +00:00
# Set indentation guides
add-highlighter global/indent-guides show-whitespaces -tab " " -spc " " -lf " " -nbsp " "
set-face global Whitespace default,default
set-face global WhitespaceIndent +d@comment
2022-08-04 23:59:32 +00:00
# Assistant
set global ui_options terminal_assistant=cat
2021-09-29 21:11:33 +00:00
# Enable line numbers
2024-05-24 14:33:21 +00:00
hook global WinCreate .* %{
addhl window/number-lines number-lines
}
2021-09-29 21:11:33 +00:00
2023-01-28 10:40:57 +00:00
set global grepcmd "rg --line-number --no-column --no-heading --color=never "
2021-09-29 21:11:33 +00:00
2024-01-21 08:55:06 +00:00
# Kitty-specific options
hook -group windowing global KakBegin .* %{
set global kitty_window_type os-window
}
2021-09-29 21:11:33 +00:00
# Comment line and block
map global normal <#> ': comment-line<ret>'
map global normal <a-#> ': comment-block<ret>'
# Go to grep-jump
2022-01-30 18:49:25 +00:00
map global goto f -docstring "current grep-jump match" '<esc>: grep-jump<ret>'
2021-09-29 21:11:33 +00:00
# System clipboard interactions
hook global RegisterModified '"' %{ nop %sh{
2022-04-20 17:05:02 +00:00
printf "%s" "$kak_main_reg_dquote" | pbcopy >/dev/null 2>/dev/null &
2021-09-29 21:11:33 +00:00
}}
2024-04-26 17:16:10 +00:00
map global user P -docstring "Paste before cursor from clipboard" '! pbpaste -n | cat<ret>'
map global user p -docstring "Paste after cursor from clipboard" '<a-!> pbpaste -n | cat<ret>'
map global user R -docstring "Replace selection with text from clipboard" '<a-d>! pbpaste -n | cat<ret>'
2021-09-29 21:11:33 +00:00
define-command -params 0 -docstring "Copy line down" copyline %{
2022-04-20 17:05:02 +00:00
execute-keys -draft 'xy'%val{count}'P'
2021-09-29 21:11:33 +00:00
}
map global normal <+> -docstring "Copy line down" ': copyline<ret>'
2022-07-07 19:17:14 +00:00
define-command -params 0 -docstring "Delete current pair of brackets" delete-current-brackets %{
2021-09-29 21:11:33 +00:00
execute-keys 'm<a-:>'
execute-keys -draft '<a-S>d'
execute-keys 'H'
}
2022-07-07 19:17:14 +00:00
map global normal D ": delete-current-brackets<ret>"
2021-09-29 21:11:33 +00:00
# Disable write-to
# unalias global w
# define-command -params 0 -docstring "Writes the current file" w "write"
# Tab sizes
hook global InsertChar \t %{ exec -draft -itersel h@ }
2024-07-10 20:20:00 +00:00
set global tabstop 2
set global indentwidth 2
2021-09-29 21:11:33 +00:00
# Ctrl + a in insert mode = esc
map global insert <c-a> '<esc>'
# Tab completion
hook global InsertCompletionShow .* %{
try %{
# this command temporarily removes cursors preceded by whitespace;
# if there are no cursors left, it raises an error, does not
# continue to execute the mapping commands, and the error is eaten
# by the `try` command so no warning appears.
execute-keys -draft 'h<a-K>\h<ret>'
map window insert <tab> <c-n>
map window insert <s-tab> <c-p>
}
}
hook global InsertCompletionHide .* %{
unmap window insert <tab> <c-n>
unmap window insert <s-tab> <c-p>
}
# Enable LSP
try %{
eval %sh{test -z "$WE_STARTED_KAK" && kak-lsp --kakoune -s $kak_session}
2024-07-10 20:20:00 +00:00
set-option global lsp_cmd "kak-lsp -s %val{session}"
2021-09-29 21:11:33 +00:00
}
2024-06-11 17:43:58 +00:00
hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c|cpp|tex|latex|fsharp|ocaml|haskell|nix|scala|typst|html|css|json|markdown|templ|elixir) %{
2021-09-29 21:11:33 +00:00
lsp-enable-window
2023-04-11 11:23:47 +00:00
map window lsp N -docstring "Display the next message request" ": lsp-show-message-request-next<ret>"
2023-03-28 05:53:02 +00:00
map window normal <c-l> ": enter-user-mode lsp<ret>"
map window normal <c-h> ": lsp-hover<ret>"
map window normal <c-s-h> ": lsp-hover-buffer<ret>"
2021-09-29 21:11:33 +00:00
# lsp-auto-hover-insert-mode-enable
2022-05-12 22:57:09 +00:00
set window lsp_hover_anchor true
2024-04-07 15:38:13 +00:00
map global insert <tab> '<a-;>:try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks <lt>tab> }<ret>' -docstring 'Select next snippet placeholder'
map global object a '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
map global object <a-a> '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
map global object f '<a-semicolon>lsp-object Function Method<ret>' -docstring 'LSP function or method'
map global object t '<a-semicolon>lsp-object Class Interface Struct<ret>' -docstring 'LSP class interface or struct'
map global object d '<a-semicolon>lsp-diagnostic-object --include-warnings<ret>' -docstring 'LSP errors and warnings'
map global object D '<a-semicolon>lsp-diagnostic-object<ret>' -docstring 'LSP errors'
2021-09-29 21:11:33 +00:00
}
2024-03-01 11:03:01 +00:00
2024-04-07 15:38:13 +00:00
hook global WinSetOption filetype=(racket|rust|python|go|javascript|typescript|c|cpp|tex|latex|haskell|nix|fsharp|templ) %{
2021-09-29 21:11:33 +00:00
# Format the document if possible
2022-01-30 18:51:08 +00:00
hook window BufWritePre .* %{ lsp-formatting-sync }
2021-09-29 21:11:33 +00:00
}
2023-09-24 14:27:32 +00:00
hook global WinSetOption filetype=(rust|scala|fsharp) %{
2022-05-12 22:57:09 +00:00
# Enable inlay hints
lsp-inlay-hints-enable window
}
2023-10-10 11:53:39 +00:00
hook global WinSetOption filetype=(rust|go|fsharp|typst|scala) %{
2021-09-29 21:11:33 +00:00
hook window -group semantic-tokens BufReload .* lsp-semantic-tokens
hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens
hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens
hook -once -always window WinSetOption filetype=.* %{
remove-hooks window semantic-tokens
}
}
# <a-a> in Insert mode moves to end of line.
map global insert <a-a> '<esc>A'
2022-05-12 22:57:09 +00:00
hook global WinSetOption filetype=(fsharp) %{
set-option window comment_line "//"
# Set up formatting
2023-09-24 14:27:32 +00:00
# set-option window formatcmd "~/.dotnet/tools/fantomas --stdin --stdout"
# hook window -group fsharp-format BufWritePre .* %{ format }
2021-09-29 21:11:33 +00:00
}
hook global WinSetOption filetype=(ocaml) %{
unset-option buffer comment_line
set-option buffer comment_block_begin "(*"
set-option buffer comment_block_end "*)"
}
hook global WinSetOption filetype=(haskell) %{
set-option buffer makecmd "cabal build"
}
hook global WinSetOption filetype=(rust) %{
set-option buffer makecmd "cargo check"
}
2022-10-09 15:17:18 +00:00
hook global WinSetOption filetype=(scala) %{
# Format the document if possible
hook -group scala-fmt window BufWritePre .* %{ lsp-formatting-sync }
set window tabstop 2
set window indentwidth 2
}
2023-07-03 20:42:03 +00:00
hook global WinSetOption filetype=(typst) %{
set-option window comment_line "//"
set-option window comment_block_begin "/*"
set-option window comment_block_end "*/"
# borrow markdown's hooks
require-module markdown
hook window ModeChange pop:insert:.* -group markdown-trim-indent markdown-trim-indent
hook window InsertChar \n -group markdown-insert markdown-insert-on-new-line
hook window InsertChar \n -group markdown-indent markdown-indent-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window markdown-.+ }
}
2022-10-09 15:17:18 +00:00
define-command -params 0 -docstring "Set up build" scala-build-connect %{
lsp-execute-command 'build-connect' '"[]"'
}
define-command -params 0 -docstring "Import build" scala-build-import %{
lsp-execute-command 'build-import' '"[]"'
}
2021-09-29 21:11:33 +00:00
def -hidden insert-c-n %{
try %{
lsp-snippets-select-next-placeholders
exec '<a-;>d'
} catch %{
exec -with-hooks '<c-n>'
}
}
map global insert <c-n> "<a-;>: insert-c-n<ret>"
# Use C++ for .h headers
hook global BufCreate .*[.](h) %{
set-option buffer filetype cpp
}
hook global BufCreate .*[.]kakrc %{
set-option buffer filetype kak
}
hook global BufCreate .*[.]md %{
add-highlighter buffer/ wrap
}
2023-10-15 11:11:54 +00:00
hook global BufCreate .*[.](sc|sbt) %{
2023-04-29 23:47:01 +00:00
set-option buffer filetype scala
}
2023-07-03 20:42:03 +00:00
hook global BufCreate .*[.]typ %{
set-option buffer filetype typst
add-highlighter buffer/ wrap
}
2024-04-07 15:38:13 +00:00
hook global BufCreate .*[.]templ %{
set-option buffer filetype templ
set-option window comment_line "//"
}
2021-09-29 21:11:33 +00:00
hook global BufOpenFile .* %{
modeline-parse
}
map global normal <a-[> ':inc-dec-modify-numbers + %val{count}<ret>'
map global normal <a-]> ':inc-dec-modify-numbers - %val{count}<ret>'