# Manually merge and source plugins eval %sh{ cat $(find "$kak_config/autosource" -name '*\.kak') kak-lsp --kakoune -s $kak_session } # Initialization decl -hidden regex curword decl str termcmd 'kitty -1 sh -c' set global ui_options ncurses_assistant=none set global scrolloff 7,7 set global autoreload yes set global kitty_window_type kitty 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}▸' set global connect_source "%val{config}/autosource/splug" set global connect_shell elvish set global fzf_implementation sk set global fzf_file_command fd set global fzf_highlighter bat unalias global e edit alias global e edit-or-dir alias global bd delete-buffer alias global bf buffer-first alias global bl buffer-last alias global bo buffer-only alias global bo! buffer-only-force alias global sw sudo-write alias global cdb change-directory-current-buffer alias global f find alias global c connect-terminal face global LineNumbersWrapped black addhl global/ number-lines -hlcursor -separator ' ' addhl global/ column 80 default,rgb:303030 addhl global/ regex '\h+$' 0:default,red addhl global/ regex \b(TODO|FIXME|XXX|NOTE)\b 0:default+rb addhl global/ show-matching addhl global/ wrap -word -indent -marker '' addhl global/ dynregex '%opt{curword}' 0:+b # 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 'add phantom selection' f ': phantom-sel-add-selection' map global user -docstring 'clear all phantom selections' ': phantom-sel-select-all: phantom-sel-clear' map global user -docstring 'next phantom selection' F ': phantom-sel-iterate-next' map global user -docstring 'previous phantom selection' ': phantom-sel-iterate-prev' map global normal -docstring 'select view' ': select-view' map global view -docstring 'select view' s ': select-view' map global user -docstring 'select selection on each line' s ': keep-selection-each-line' map global user -docstring 'drop selection on each line' S ': drop-selection-each-line' map global user -docstring 'add mark' m ': mark-word' map global user -docstring 'clear marks' M ': mark-clear' map global user -docstring 'replace mode' r ': replace' map global normal ': fzf-mode' map global user -docstring 'expand selection' e ': expand' map global user -docstring 'expand repeat' E ': expand-repeat' map global user -docstring 'buffers…' b ': enter-buffers-mode' map global user -docstring 'buffers (lock)…' B ': enter-user-mode -lock buffers' map global user -docstring "next error" l ': lint-next-error' map global user -docstring "previous error" L ': lint-previous-error' declare-user-mode surround map global user -docstring 'surround mode' ': enter-user-mode surround' map global surround -docstring 'surround' s ': surround' map global surround -docstring 'change' c ': change-surround' map global surround -docstring 'delete' d ': delete-surround' map global surround -docstring 'select tag' t ': select-surrounding-tag' map global surround -docstring 'auto-pairs surround' a ': auto-pairs-surround' declare-user-mode anchor map global normal ';' ': enter-user-mode anchor' map global anchor -docstring 'reduce to anchor' a ';' map global anchor -docstring 'reduce to cursor' c ';' map global anchor -docstring 'flip cursor and anchor' f '' map global anchor -docstring 'ensure anchor after cursor' h '' map global anchor -docstring 'ensure cursor after anchor' l '' 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 -> insert mode' c 'xclip -i -f -sel c' # Functions def toggle-highlighter -params .. -docstring 'Toggle highlighter' %{ try %{ addhl window/%arg{@} %arg{@} echo -markup {green} %arg{@} } catch %{ rmhl window/%arg{@} echo -markup {red} %arg{@} } } def lint-on-write -docstring 'Activate linting on buffer write' %{ lint-enable hook buffer BufWritePost .* lint } def format-on-write -docstring 'Format buffer on write' %{ hook buffer BufWritePost .* format } def lsp-engage -docstring 'Enable language server' %{ lsp-enable lsp-auto-hover-enable map global user -docstring 'Enter lsp user mode' l ': enter-user-mode lsp' map global user -docstring 'Lock lsp user mode' L ': enter-user-mode -lock lsp' } def no-tabs -params 0..1 -docstring 'Indent with spaces' %{ eval %sh{ [ -n "$1" ] && printf %s " set buffer indentwidth $1 set buffer tabstop $1 set buffer softtabstop $1 " } expandtab 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 WinDisplay .* info-buffers hook global NormalIdle .* %{ try %{ exec -draft 'w: palette-status' } } hook global BufWritePost .* %{ git show-diff } hook global BufReload .* %{ git show-diff } hook global WinCreate .* %{ auto-pairs-enable search-highlighter-enable } hook global BufWritePre .* %{ nop %sh{ mkdir -p "$(dirname "$kak_buffile")" }} hook global NormalIdle .* %{ eval -draft %{ try %{ exec w \A\w+\z set buffer curword "\b\Q%val{selection}\E\b" } catch %{ set buffer curword '' } } } # 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 window/java } hook global BufCreate .*\.rasi %{ set buffer filetype css } # Filetype settings hook global WinSetOption filetype=sh %{ set buffer lintcmd 'shellcheck -x -fgcc' lint-on-write } hook global WinSetOption filetype=elvish %{ no-tabs 2 } hook global WinSetOption filetype=(go|rust|python) %{ lsp-engage set global lsp_server_configuration pyls.plugins.jedi_completion.include_params=false hook window BufWritePre .* lsp-formatting-sync } hook global WinSetOption filetype=nim %{ set buffer gdb_program 'nim-gdb' set buffer formatcmd "nimpretty ${kak_buffile}" set buffer makecmd 'nimble build' # set buffer lintcmd "sh -c 'cp -f $0 $0.nim;nim --stdout --colors:off --hints:off --path:$(dirname ${kak_buffile}) check $0 | sed \"s/(/:/;s/, /:/;s/)/:/\" | sed \":a;N;/\n[buf.nim]/!s/\n//;ta;P;D\"'" # set buffer lintcmd "sh -c 'nim --stdout --hints:off check $0 | sed \'s/(/:/;s/, /:/;s/)/:/\''" # lint-on-write # format-on-write no-tabs 2 }