# Daniel's Personal kakrc # Author: Daniel Fichtinger # See README.md for explanations. # TODO: set up auto root discovery on KakBegin declare-option -hidden bool on_server %sh{ if [ -z "$KAK_ON_LOCAL" ]; then printf 'true' else printf 'false' fi } define-command -override true nop define-command -override false fail require-module ui-mode require-module colemak require-module clipboard require-module root try %{ %opt{on_server} set-option global clipboard_copy_cmd % colorscheme ashen-local } catch %{ source %exp{%val{config}/extra.kak} } require-module surround require-module expand require-module ficgrep require-module byline set-option global scrolloff 3,3 try %{ set-option global ashen_dynamic_cursor true set-option global ashen_eol_cursor true } # disable clippy set-option -add global ui_options terminal_assistant=none # This gets overridden by editorconfig but we set sane default anyways set-option global tabstop 4 set-option global indentwidth 4 hook -once global WinSetOption filetype=kak %{ # highlight extra keywords declare-option str-list extra_kak_keywords addhl decl def compl eval exec rmhl rmhooks face set unset eval %sh{ join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; } if [ -n "$kak_opt_extra_kak_keywords" ]; then printf '%s' "add-highlighter shared/kakrc/code/extra_keywords regex (?:\s|\A)\K($(join "${kak_opt_extra_kak_keywords}" '|'))(?:(?=\s)|\z) 0:keyword" fi } } hook global WinSetOption filetype=kak %{ # make brackets gray a-la Ashen add-highlighter window/bracket regex [\[\]\(\)\{\}]{1} 0:rgb:737373 add-highlighter window/info regex '#\h*(INFO|NOTE|TODO|PERF|OPTIMIZE|PERFORMANCE|QUESTION|ASK):[^\n]*' 1:+a@ts_info add-highlighter window/hint regex '#\h*(HINT|MARK|PASSED|STUB|MOCK):[^\n]*' 1:+a@ts_hint add-highlighter window/warning regex '#\h*(HACK|WARN|WARNING|TEST|TEMPHACK|WARN|WARNING|TEST|TEMPHACK|WARN|WARNING|TEST|TEMPHACK|WARN|WARNING|TEST|TEMP):[^\n]*' 1:+a@ts_warning add-highlighter window/error regex '#\h*(BUG|FIXME|ISSUE|XXX|FIX|SAFETY|FIXIT|FAILED|DEBUG|INVARIANT|COMPLIANCE):[^\n]*' 1:+a@ts_error # special highlighting for escaped goodies in regex # add-highlighter window/regex-escaped regex \\[\[\]\(\)\{\}fnrtv0\\dwshDWSH] 0:rgb:e5e5e5 } # default window settings # wrap enabled # scrolloff enabled hook global WinCreate .* %{ ui-wrap-enable # TODO: fix ui-scrolloff-enable and use that instead ui-scrolloff-toggle add-highlighter window/number-lines number-lines -hlcursor -relative -separator " " # only-trailing is nice QOL otherwise it gets hard to read the screen # and it makes it easy to see trailing spaces add-highlighter window/show-whitespaces show-whitespaces -only-trailing add-highlighter window/show-matching show-matching # TODO: update plugin so it auto clears if escaped out of search, # but if search is accepted then auto clear on in normal mode? require-module search-highlight set window search_highlight_face %exp{%opt{orange_golden}+u} search-highlight-enable } # convenience mappings # quitting & saving map -docstring "quit" global user q ": q" map -docstring "quit" global normal ": q" map -docstring "force quit" global user Q ": q!" map -docstring "force quit" global normal ": q!" map -docstring "kill session" global normal ':kill' map -docstring "force kill session" global normal ':kill!' map -docstring "save" global normal ": write" map -docstring "save" global normal ": write!" # buffer operations map -docstring "close current buffer" global user x ": db" map -docstring "goto previous buffer" global user m ": bp" map -docstring "goto next buffer" global user i ": bn" map -docstring "goto previous buffer" global normal ": bp" map -docstring "goto next buffer" global normal ": bn" # trim whitespace map global normal _ # comments define-command comment-line-as-block %{ execute-keys -draft 'xs[^\n]: comment-block' } define-command smart-comment %{ evaluate-commands %sh{ if [ -z "${kak_opt_comment_line}" ]; then echo "comment-line-as-block" else echo "comment-line" fi } } map -docstring "smart comment" global normal "#" ": smart-comment" map -docstring "comment block" global normal "" ": comment-block" # formatting map -docstring "format" global normal = ": format-buffer" map -docstring "format" global normal ": format-selections" # Case-insensitive Search map -docstring 'case insensitive search' global user '/' /(?i) map -docstring 'case insensitive backward search' global user '' (?i) map -docstring 'case insensitive extend search' global user '?' ?(?i) map -docstring 'case insensitive backward extend-search' global user '' (?i) # TODO: how to bind these to goto mode while respecting g/G?? map -docstring 'Select to file end' global user N "GjL" map -docstring 'Extend to file end' global user n "gjl" define-command -docstring "Create a scratch buffer" scratch %{ edit -scratch } alias global s scratch define-command -params 1 -docstring "Set buffer filetype" filetype %{ set-option buffer filetype %arg{1} } alias global ft filetype alias global lang filetype map global normal '"_' define-command goto-debug %{ buffer *debug* try %{ ui-scrolloff-disable execute-keys 'gj' } } map -docstring 'open debug buffer' global user d ':goto-debug' declare-filetype-mode kak require-module repl map -docstring 'execute selection' global kak x ': execute-selection' map -docstring 'execute file' global kak X ': execute-file' # jumplist map -docstring 'jump forward' global normal map -docstring 'save to jumplist' global normal # selection saving map -docstring 'add selection' global normal Y a # open URL require-module url-open map -docstring "Open URL" global goto u ': url-open' # apply and validate niri config hook global BufWritePost .*/\.config/niri/.*\.kdl(##.+)? %{ eval %sh{ yadm alt >/dev/null if ! niri validate >/dev/null; then echo 'info "Error in niri config, check *debug*"' fi } }