### Plugins ### evaluate-commands %sh{ plugins="$kak_config/plugins" mkdir -p "$plugins" [ ! -e "$plugins/plug.kak" ] && \ git clone -q https://github.com/andreyorst/plug.kak.git "$plugins/plug.kak" printf "%s\n" "source '$plugins/plug.kak/rc/plug.kak'" } plug "andreyorst/plug.kak" noload plug "andreyorst/smarttab.kak" defer smarttab %{ set-option global softtabstop 4 } plug "occivink/kakoune-sudo-write" plug "kak-lsp/kak-lsp" do %{ cargo install --locked --force --path . } plug "h-youhei/kakoune-surround" plug "eburghar/kakpipe" do %{ cargo install --force --path . --root ~/.local } config %{ require-module kakpipe } plug "gustavo-hms/luar" %{ require-module luar } plug "gustavo-hms/peneira" %{ require-module peneira } plug "caksoylar/kakoune-focus" config %{ # configuration here } plug "jtrv/grep-write.kak" # # Color Themes plug "tinted-theming/base16-kakoune" theme plug "https://git.sr.ht/~hadronized/kakoune-tree-sitter-themes" theme ### End Of Plugins ### ## Treesitter ## eval %sh{ kak-tree-sitter -dksvvv --with-highlighting --with-text-objects --init $kak_session } ## Highlighting ## hook global WinCreate .* %{ add-highlighter window/number-lines number-lines -relative -hlcursor} add-highlighter global/ show-matching add-highlighter global/ show-whitespaces -spc " " -nbsp "" ## Wrapping ## add-highlighter global/ wrap -word -indent ## Formatting ## define-command enable-autofmt -docstring 'enable autoformatting of buffer' %{ hook global -group autofmt BufSetOption filetype=(zig) %{ set-option buffer formatcmd 'zig fmt --stdin' hook -group autofmt buffer BufOpenFile .* %{ format } hook -group autofmt buffer BufWritePre .* %{ format } } hook global -group autofmt BufSetOption filetype=(html) %{ set-option buffer formatcmd 'prettier --tab-width 4 --parser html' hook -group autofmt buffer BufOpenFile .* %{ format } hook -group autofmt buffer BufWritePre .* %{ format } } hook global -group autofmt BufSetOption filetype=(css) %{ set-option buffer formatcmd 'prettier --tab-width 4 --parser css' hook -group autofmt buffer BufOpenFile .* %{ format } hook -group autofmt buffer BufWritePre .* %{ format } } hook global -group autofmt BufSetOption filetype=(javascript) %{ set-option buffer formatcmd 'prettier --tab-width 4 --parser typescript' hook -group autofmt buffer BufOpenFile .* %{ format } hook -group autofmt buffer BufWritePre .* %{ format } } hook global -group autofmt BufSetOption filetype=(go) %{ set-option buffer formatcmd 'gofmt' hook -group autofmt buffer BufOpenFile .* %{ format } hook -group autofmt buffer BufWritePre .* %{ format } } } define-command disable-autofmt -docstring 'disable autoformatting of buffer' %{ remove-hooks global autofmt } # enable-autofmt ## Indentation ## set global tabstop 4 set global indentwidth 4 hook global WinSetOption filetype=.* expandtab hook global WinSetOption filetype=(makefile|gas|go) noexpandtab # hook global BufCreate .* %{ # editorconfig-load # autoconfigtab # } define-command set-spell -docstring 'Enable spellcheck' %{ # hook -group spellcheck global BufOpenFile .* %{ hook -group spellcheck buffer InsertChar .* %{ evaluate-commands %{ spell } } hook -group spellcheck buffer InsertDelete .* %{ evaluate-commands %{ spell } } # } } define-command set-nospell -docstring 'Disable spellcheck' %{ remove-hooks buffer spellcheck } define-command sleuth -docstring 'Heuristically set buffer options' %{ try %{ evaluate-commands -draft %{ info 'trying' # Search the first indent level execute-keys 'gg' '/' '^\h+' '' # Tab vs. Space # https://youtu.be/V7PLxL8jIl8 try %{ execute-keys '' '\t' '' #set-option buffer indentwidth 0 noexpandtab } catch %{ set-option buffer indentwidth %val{selection_length} expandtab } } } } define-command git-status -docstring 'Show git diff' %{ hook -group git-status global BufOpenFile .* %{ git show-diff } hook -group git-status global BufWritePost .* %{ git show-diff } } define-command disable-git-status -docstring 'Disable git diff gutter' %{ remove-hooks global git-status } define-command sleuth-enable -docstring 'Enable sleuth' %{ # Run sleuth when opening and saving files. hook -group sleuth global BufOpenFile .* %{ sleuth } hook -group sleuth global BufWritePost .* %{ sleuth } } define-command sleuth-disable -docstring 'Disable sleuth' %{ remove-hooks global sleuth } sleuth-enable ## LSP ## lsp-enable lsp-inlay-diagnostics-enable global set-option global lsp_auto_highlight_references true set-option global lsp_hover_anchor true lsp-auto-signature-help-enable lsp-inlay-hints-enable global map global user k ':lsp-hover' hook global WinSetOption filetype=(c|cpp|zig|rust|python|ruby|lua|java|html|css) %{ 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 } } face global InfoDefault Information face global InfoBlock Information face global InfoBlockQuote Information face global InfoBullet Information face global InfoHeader Information face global InfoLink Information face global InfoLinkMono Information face global InfoMono Information face global InfoRule Information face global InfoDiagnosticError Information face global InfoDiagnosticHint Information face global InfoDiagnosticInformation Information face global InfoDiagnosticWarning Information hook -group lsp-filetype-swift global BufSetOption filetype=swift %{ set-option buffer lsp_servers %{ [sourcekit-lsp] root_globs = [".git", ".hg"] } } hook -group lsp-filetype-typst global BufSetOption filetype=typst %{ set-option buffer lsp_servers %{ [tinymist] root_globs = [".git", ".hg"] args = ["lsp"] settings_section = "_" [tinymist.settings._] # See https://myriad-dreamin.github.io/tinymist/configurations.html exportPdf = "onType" # formatterMode = "typstyle" # previewFeature = "disable" } } set-option global lsp_config %{ } declare-option str findcmd 'fd' define-command -docstring 'Find file' fd -params 1 %{ edit %arg{1} } complete-command fd shell-script-candidates %opt{findcmd} declare-option -hidden str-list last_command define-command -hidden run_cmd -params .. %{ kakpipe -n %arg{1} %arg{@} } define-command -hidden run_cmd_bg -params .. %{ kakpipe-bg -n %arg{1} %arg{@} } define-command -docstring 'run command in fifo' cmd -params .. %{ run_cmd %arg{@} set-option global last_command %arg{@} set-option buffer filetype cmd } define-command -docstring 'run command in fifo (background buffer)' cmd-bg -params .. %{ run_cmd_bg %arg{@} set-option global last_command %arg{@} set-option buffer filetype cmd } define-command -docstring 'rerun last command' rcmd %{ cmd %opt{last_command} } define-command -docstring 'rerun last command in background' rcmd-bg %{ cmd-bg %opt{last_command} } define-command -hidden cmd-jump %{ evaluate-commands -save-regs a %{ try %{ execute-keys 'ght"ay' evaluate-commands -try-client %opt{jumpclient} -verbatim -- edit -existing -- %reg{a} try %{ focus %opt{jumpclient} } } catch %{ jump } } } hook -group cmd-highlight global WinSetOption filetype=cmd %{ add-highlighter window/cmd group add-highlighter window/cmd/location regex "^([^:\n]+):(\d+):(\d+)?" 1:cyan 2:green 3:green add-highlighter window/cmd/path regex "^([^:\n]+[^/])$" 1:cyan add-highlighter window/cmd/ line %{%opt{jump_current_line}} default+b hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cmd } } hook global WinSetOption filetype=cmd %{ hook buffer -group cmd-hooks NormalKey cmd-jump hook -once -always window WinSetOption filetype=.* %{ remove-hooks buffer cmd-hooks } } define-command fzf-buffer -docstring 'Invoke fzf to select a buffer' %{ evaluate-commands %sh{ tmux split-window -l 20% "(printf \"%s\n\" $kak_quoted_buflist | fzf --bind 'focus:execute-silent(echo \"eval -client $kak_client %{ e {} }\" | kak -p $kak_session)' || echo \"$kak_buffile\") | xargs -I{} echo \"eval -client $kak_client %{ e '{}' }\" | /usr/bin/kak -p $kak_session" } } define-command -docstring 'Print Working Directory' -params 0 pwd %{ evaluate-commands echo %sh{ echo "$(pwd)"} } # define-command -docstring 'copy to clipboard' xcopy %{ # execute-keys 'xclip -selection clipboard -i' # } # define-command -docstring 'paste from clipboard' xpaste %{ # evaluate-commands -save-regs '"' %{ # set-register dquote %sh{ xclip -selection clipboard -o } # execute-keys 'p' # } # } define-command -docstring 'copy to clipboard' xcopy %{ execute-keys 'wl-copy' } define-command -docstring 'paste from clipboard' xpaste %{ evaluate-commands -save-regs '"' %{ set-register dquote %sh{ wl-paste } execute-keys 'P' } } declare-user-mode config map -docstring 'enter config mode' global user e ':enter-user-mode config' map -docstring 'edit kakoune config' global config k ':e ~/.config/kak/kakrc' map -docstring 'edit tmux config' global config t ':e ~/.tmux.conf' map -docstring 'edit bash config' global config b ':e ~/.bashrc' map -docstring 'edit scripts folder' global config s ':cd ~/.scripts:peneira-files' map -docstring 'edit .config folder' global config c ':cd ~/.config:peneira-files' declare-user-mode buffer map -docstring 'enter buffer mode' global user b ':enter-user-mode buffer' map -docstring 'next buffer' global buffer n ':buffer-next' map -docstring 'previous buffer' global buffer p ':buffer-previous' map -docstring 'close current buffer' global buffer d ':delete-buffer!' map -docstring 'write and close current buffer' global buffer w ':w:db' map -docstring 'list and select a buffer' global buffer b ':fzf-buffer' declare-user-mode find map -docstring 'enter find mode' global user f ':enter-user-mode find' map -docstring 'find files' global find f ':peneira-files' map -docstring 'find tags for the current project' global find t ':peneira-symbols' map -docstring 'find files in current directory' global find F ':peneira-local-files' map -docstring 'enter lsp mode' global user l ':enter-user-mode lsp' map -docstring 'goto definition (tag)' global lsp t 'w:ctags-search' map -docstring 'enter treesitter mode' global user t ':enter-user-mode tree-sitter' # map -docstring 'enter treesitter search mode' global user s ':enter-user-mode tree-sitter-search' declare-user-mode tmux map -docstring 'enter tmux/window mode' global user w ':enter-user-mode tmux' map -docstring 'vertical split' global tmux v ':tmux-terminal-horizontal kak -c %val{session}' map -docstring 'horizontal split' global tmux h ':tmux-terminal-vertical kak -c %val{session}' map -docstring 'new tab' global tmux t ':tmux-terminal-window kak -c %val{session}' map -docstring 'vertical terminal split' global tmux V ':tmux-repl-horizontal bash' map -docstring 'horizontal terminal split' global tmux H ':tmux-repl-vertical bash' map -docstring 'new terminal tab' global tmux T ':tmux-repl-window' map -docstring 'new git window' global tmux g ':tmux-terminal-window lazygit' map -docstring 'enter man mode' global user m ':enter-user-mode man' #map -docstring 'clipboard yank' global user y 'clip.exe' map -docstring 'clipboard yank' global user y ':xcopy' #map -docstring 'clipboard paste' global user p '|powershell.exe -C Get-Clipboard | tr -d "\r"' map -docstring 'clipboard paste' global user p ':xpaste' map -docstring 'toggle comments' global user c ':comment-line' declare-user-mode subvert map global user s ':enter-user-mode subvert' -docstring 'enter subvert user mode' map global subvert a '| kak-subvert ada ' -docstring 'convert to Ada case' map global subvert c '| kak-subvert camel ' -docstring 'convert to camel case' map global subvert k '| kak-subvert kebab ' -docstring 'convert to kebab case' map global subvert p '| kak-subvert pascal ' -docstring 'convert to pascal case' map global subvert . '| kak-subvert sentence ' -docstring 'convert to sentence case' map global subvert s '| kak-subvert snake ' -docstring 'convert to snake case' map global subvert S '| kak-subvert screaming ' -docstring 'convert to screaming case' map global subvert t '| kak-subvert train ' -docstring 'convert to train case' map global subvert T '| kak-subvert title ' -docstring 'convert to title case' declare-user-mode spell map -docstring 'enter spell mode' global user S ':enter-user-mode spell' map -docstring 'enable spell check' global spell s ':spell' map -docstring 'clear spell check' global spell c ':spell-clear' map -docstring 'next spell check' global spell n ':spell-next' map -docstring 'spell check replacements' global spell r ':spell-replace' map -docstring 'quit kakoune' global user q ':q!' try %{ colorscheme %sh{ ruby -e "time = Time.new; if time.hour < 20 and time.hour > 6 then puts 'dawnfox' else puts 'carbonfox' end" } } catch %{ colorscheme carbonfox }