# External plugins eval %sh{ kak-lsp --kakoune -s $kak_session colorcol } # Initialization require-module connect-skim decl -hidden regex curword decl -hidden regex curword_word_class set global ui_options ncurses_assistant=none set global scrolloff 7,7 set global autoreload yes set global grepcmd 'rg -iHL --column' set global modelinefmt '%opt{modeline_git_branch} %val{bufname} %val{cursor_line}:%val{cursor_char_column} {{mode_info}} {{context_info}}◂%val{client}⊙%val{session}▸' alias global sw sudo-write alias global cdb change-directory-current-buffer alias global f find alias global g grep alias global s sort-selections alias global explore-files skim-files alias global explore-buffers skim-buffers face global LineNumbersWrapped black face global CurWord +b addhl global/number-lines number-lines -hlcursor -separator ' ' addhl global/ruler column 80 default,rgb:303030 addhl global/trailing-whitespace regex '\h+$' 0:default,red addhl global/todo regex \b(TODO|FIXME|XXX|NOTE)\b 0:default+rb addhl global/matching-brackets show-matching addhl global/wrap wrap -word -indent -marker '' addhl global/current-word dynregex '%opt{curword}' 0:CurWord # Keybinds map global normal , map global normal -docstring 'remove all sels except main' map global normal -docstring 'remove main sel' map global normal -docstring 'comment line' '#' ': comment-line' map global normal -docstring 'comment block' '' ': comment-block' map global normal -docstring 'delete to end of line' D d map global normal -docstring 'yank to end of line' Y map global user -docstring 'replay macro' . q map global user -docstring 'record macro' Q map global normal w ': word-select-next-word' map global normal ': word-select-next-big-word' map global normal q ': word-select-previous-word' map global normal ': word-select-previous-big-word' map global normal Q B map global normal map global user -docstring 'replace mode' r ': replace' map global user -docstring 'expand selection' e ': expand' map global user -docstring 'expand repeat' E ': expand-repeat' map global normal -docstring 'buffers…' b ': enter-buffers-mode' map global normal -docstring 'buffers (lock)…' B ': enter-user-mode -lock buffers' map global normal -docstring 'select buffer' ': explore-buffers' declare-user-mode anchor map global normal ';' ': enter-user-mode anchor' map global anchor -docstring 'ensure anchor after cursor' h '' map global anchor -docstring 'ensure cursor after anchor' l '' map global anchor -docstring 'flip cursor and anchor' f '' map global anchor -docstring 'reduce to anchor' a ';' map global anchor -docstring 'reduce to cursor' c ';' map global anchor -docstring 'select cursor and anchor' s '' declare-user-mode clipboard map global normal ',' ': enter-user-mode clipboard' map global clipboard -docstring 'clip-paste after' p 'xsel -b -o' map global clipboard -docstring 'clip-paste before' P '!xsel -b -o' map global clipboard -docstring 'clip-paste replace' R '|xsel -b -o' map global clipboard -docstring 'clip-yank' y 'xclip -i -f -sel c' map global clipboard -docstring 'clip-cut' d 'xclip -i -f -sel c' map global clipboard -docstring 'clip-cut -> insert mode' c 'xclip -i -f -sel c' # Functions def type -params 1 -docstring 'Set buffer filetype' %{ set buffer filetype %arg{1} } def lint-engage -docstring 'Enable linting' %{ lint-enable map global user -docstring "next error" l ': lint-next-error' map global user -docstring "previous error" L ': lint-previous-error' } def lsp-engage -docstring 'Enable language server' %{ lsp-enable lsp-auto-hover-enable map global user -docstring 'Enter lsp user mode' ': enter-user-mode lsp' } def lsp-semantic-highlighting -docstring 'Enable semantic highlighting' %{ 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 } } def lint-on-write -docstring 'Activate linting on buffer write' %{ lint-engage hook buffer BufWritePost .* lint } def set-indent -params 1 -docstring 'Set indentation width' %{ set buffer indentwidth %arg{1} set buffer tabstop %arg{1} set buffer softtabstop %arg{1} } def no-tabs -params 1 -docstring 'Indent with spaces' %{ expandtab set-indent %arg{1} hook buffer InsertKey %{ try %{ exec -draft h^\h+ exec -with-hooks }} } def clean-trailing-whitespace -docstring 'Remove trailing whitespace' %{ try %{ exec -draft '%s\h+$d' } } # Hooks hook global WinCreate .* %{ smarttab readline-enable colorcol-enable colorcol-auto-refresh } hook global KakBegin .* %{ state-save-reg-load colon state-save-reg-load pipe state-save-reg-load slash } hook global KakEnd .* %{ state-save-reg-save colon state-save-reg-save pipe state-save-reg-save slash } hook global WinDisplay .* info-buffers hook global NormalIdle .* %{ try %{ exec -draft 'w: palette-status' } } hook global BufWritePre .* %{ nop %sh{ mkdir -p "$(dirname "$kak_buffile")" }} hook global NormalIdle .* %{ eval -draft %{ try %{ exec w set buffer curword "(?/dev/null 1>/dev/null && printf %s " hook global BufWritePost .* %{ git show-diff } hook global BufReload .* %{ git show-diff } "} hook global ModuleLoaded kitty %{ set global kitty_window_type kitty } # Filetype detection hook global BufCreate .*srcpkgs/.+/template$ %{ set buffer filetype sh def xgensum %{ %sh{ xgensum -i "$kak_buffile" } } } hook global BufCreate .*/\.?((sx|xinit)(rc)?|profile) %{ set buffer filetype sh } hook global BufCreate .*\.ino %{ set buffer filetype cpp } hook global BufCreate .*\.cs %{ addhl buffer/java } hook global BufCreate .*\.rasi %{ set buffer filetype css } # Filetype settings hook global WinSetOption filetype=sh %{ set buffer lintcmd 'shellcheck --norc -x -f gcc' lint-on-write } hook global WinSetOption filetype=elvish %{ no-tabs 2 } hook global WinSetOption filetype=(go|c|cpp) %{ lsp-engage } hook global WinSetOption filetype=rust %{ lsp-engage hook window -group rust-inlay-hints BufReload .* rust-analyzer-inlay-hints hook window -group rust-inlay-hints NormalIdle .* rust-analyzer-inlay-hints hook window -group rust-inlay-hints InsertIdle .* rust-analyzer-inlay-hints hook -once -always window WinSetOption filetype=.* %{ remove-hooks window rust-inlay-hints } } hook global WinSetOption filetype=markdown %{ set buffer formatcmd 'prettier --parser markdown' def -docstring 'render current buffer' render %{ exec ": connect-terminal glow -s dark %val{buffile} | ${PAGER}" } } hook global WinSetOption filetype=python %{ set global lsp_server_configuration pyls.plugins.jedi_completion.include_params=false lsp-engage } hook global WinSetOption filetype=nim %{ set buffer gdb_program 'nim-gdb' set buffer formatcmd 'nimprettify' set buffer makecmd 'nimble build' no-tabs 2 lsp-engage }