#________ Options ___________ # Keep status bar in the default place set-option -add global ui_options terminal_status_on_top=false # Set an invisible padding char set-option -add global ui_options terminal_padding_char= # Always keep two lines and two columns displayed around the cursor set-option global scrolloff 2,2 # No assistant set-option -add global ui_options terminal_assistant=cat hook global ModuleLoaded x11 %{ set-option global termcmd 'st -e dash -c ' } # Set st as default terminal # __________ Commands __________ define-command -override lf-open \ -docstring 'pick a file with lf' %{ terminal dash -c %{ # Local variables kak_buffile=$1 kak_session=$2 kak_client=$3 # Create temporary file for selection lf_tmp=$(mktemp "${TMPDIR:-/tmp}"/lf-open.XXXXXXXXXX) # Get working directory of current buffer kak_pwd=$(dirname "${kak_buffile}") # Pick a file with lf $(lf -selection-path "${lf_tmp}" "${kak_pwd}") # Get first line of selection file (ignoring multiple selections) filename=$(head -n 1 "${lf_tmp}") # Only echo a command back if there was a selection if [ -n "$filename" ]; then # Construct the command to pass to kakoune kak_cmd="evaluate-commands -client $kak_client edit $filename" # Echo the command back to the parent session echo $kak_cmd | kak -p $kak_session fi } -- %val{buffile} %val{session} %val{client} } define-command -override cron \ -docstring 'edit cron services' %{ execute-keys ': e ~/.config/cron/' } define-command -override colorscheme-config \ -docstring 'edit colorscheme configuration file' %{ edit "%val{config}/autoload/colorscheme.kak" } define-command -override config \ -docstring 'edit kakoune main configuration file' %{ edit "%val{config}/kakrc" } define-command -override rss \ -docstring 'edit rss feeds file' %{ edit '~/.config/newsraft/feeds' } define-command -override latin \ -docstring 'edit latin-portuguese dictionary' %{ edit '~/Projects/markdown/latim-portugues.md' } define-command -override remind \ -docstring 'Edit reminders' %{ execute-keys ': e /home/radio/.local/share/reminders/' } define-command -override parse-latin \ -docstring 'Parse latin text, replacing ^ for short and ~ for long' %{ execute-keys '|sed y/ãẽĩõũ/āēīōū/' execute-keys '|sed y/âêîôû/ăěĭŏŭ/' } define-command -params 1 -override tex-project \ -docstring 'edit or create a new tex-project' %{ evaluate-commands 'cd ~/Projects/latex/' nop %sh{ mkdir -p "$1" } evaluate-commands 'cd "%arg{1}"' nop %sh{ [ -s $1.tex ] || cat ../example/example.tex \ | sed "s/example/$1/" > "$1.tex"; } edit "%arg{1}.tex" execute-keys '16gA' } define-command -override open-buffer-picker \ -docstring 'open-buffer-picker: Opens buffer picker.' %{ prompt buffer: -buffer-completion %{ buffer %val{text} } } define-command -override toggle-readonly \ -docstring 'changes buffer readonly option current state' %{ set-option buffer readonly %sh{ "$kak_opt_readonly" && echo false || echo true } } define-command -override qalc \ -params .. %{echo %sh{qalc ${@}}} \ -docstring 'compute equation with Qalculate!' complete-command qalc shell-script-candidates %{ { echo $(qalc --list-functions | head -n -3) echo $(qalc --list-variables | head -n -3) } | tr ' ' '\n' | sort | uniq } define-command diff-buffers -override -params 2 \ -docstring 'show the diff of two buffers'%{ evaluate-commands %sh{ file1=$(mktemp) file2=$(mktemp) echo " evaluate-commands -buffer '$1' write -force $file1 evaluate-commands -buffer '$2' write -force $file2 edit! -scratch *diff-buffers* set buffer filetype diff set-register | 'diff -u $file1 $file2; rm $file1 $file2' execute-keys !gg " }} complete-command diff-buffers buffer # __________ Hidden commands __________ define-command -override -hidden edit-from-file %{ execute-keys ":edit %sh{dirname $kak_buffile}/" } define-command -override -hidden spawn-terminal-from-file %{ set-register b "%sh{pwd}" change-directory "%sh{dirname $kak_buffile}" evaluate-commands 'terminal dash' change-directory "%reg{b}" } # Spawn a terminal in the current buffer's file directory # __________ Mappings __________ map global normal ': buffer-previous' map global normal Y ': yank-helperu' \ -docstring 'yank non-selections' map global normal D '"ad%d"a' \ -docstring 'yank and delete non-selections' map global normal '"ad%"a' \ -docstring 'delete non-selections (not yanking)' map global user ': spawn-terminal-from-file' \ -docstring "open a new terminal within the current file's directory" map global user c ': comment-line' \ -docstring 'comment-line' map global user ': comment-block' \ -docstring 'comment-block' map global user D '| date +"%d %b %Y %a" -f -' \ -docstring 'parse date to 01 Feb 2001 Tue format' map global user d ': lf-open' \ -docstring 'pick a file with lf' map global user e ":edit-from-file" \ -docstring "edit a file, searching from current file's directory" map global user l ': enter-user-mode lsp' \ -docstring 'enter lsp user mode' try %{ declare-user-mode open-sel } map global user o ': enter-user-mode open-sel' \ -docstring 'enter open-sel user mode' map global user r ': remind' \ -docstring 'edit reminders' map global user s ': enter-user-mode surround' \ -docstring 'enter surround user mode' map global user u ': echo -markup "{Information}U+%sh{printf ''%04x'' ""$kak_cursor_char_value""}"' \ -docstring 'show the value of the selected unicode char' map global user q ': delete-buffer' \ -docstring 'delete current buffer' map global user Q ': delete-buffer!' \ -docstring 'delete current buffer' map global open-sel b '$ icecat $kak_reg_dot & disown' \ -docstring 'on browser' map global open-sel m '$ mpv $kak_reg_dot & disown' \ -docstring 'on mpv' map global goto b ': open-buffer-picker' \ -docstring 'buffer' map global normal = ': prompt math: %{exec "a %val{text}esc>|qalc -t +u8 -f -ret>"}' \ -docstring 'Replace selection by the result of some operation over it' map global object 'c,'\ -docstring 'whitespaces' try %{ declare-user-mode git } map global git l ': git log' -docstring 'log' map global git c ': git commit' -docstring 'commit' map global git d ': git diff' -docstring 'diff' map global git s ': git status' -docstring 'status' map global git h ': git show-diff' -docstring 'show diff' map global git H ': git-hide-diff' -docstring 'hide diff' # try %{ declare-user-mode gdb } # map global gdb ': gdb-session-new-defaults' -docstring 'new session' # map global gdb ': gdb-session-stop' -docstring 'stop session' # map global gdb r ': gdb-run' -docstring 'run' # map global gdb R ': gdb-cmd start' -docstring 'start' # map global gdb k ': gdb-cmd kill' -docstring 'kill' # map global gdb s ': gdb-step' -docstring 'step' # map global gdb n ': gdb-next' -docstring 'next line' # map global gdb f ': gdb-finish' -docstring 'finish' # map global gdb c ': gdb-continue' -docstring 'continue' # swap with C? # map global gdb C ': gdb-continue-or-run' -docstring 'continue/run' # map global gdb j ': gdb-jump-to-location' -docstring 'jump to IP' # map global gdb J ': gdb-toggle-autojump' -docstring 'toggle autojump' # map global gdb b ': gdb-toggle-breakpoint' -docstring 'toggle breakpoint' # map global gdb p ': gdb-print' -docstring 'print selection expression' # map global gdb t ': gdb-backtrace' -docstring 'backtrace' # map global gdb ': gdb-backtrace-up' -docstring 'backtrace ↑' # map global gdb ': gdb-backtrace-down' -docstring 'backtrace ↓' # map global gdb : ':gdb-cmd ' -docstring 'custom command' # ? # map global gdb ': gdb-to-cursor' -docstring 'to cursor' # map global gdb m ': gdb-cmd kill; make' -docstring 'kill and make' # ? # __________ Hooks __________ hook -group config global BufCreate 'kakrc' %{ set-option buffer filetype kak } # Set kakrc's filetype to kak hook -group config global BufCreate '.*\.(bash_profile|profile|bashrc|bash_aliases)' %{ set-option buffer filetype sh } # Set bash configuration file's filetype to sh hook global BufCreate '\*scratch\*' %{ execute-keys '%' } # Remove the *scratch* message hook global BufCreate .* %{ add-highlighter buffer/ number-lines -relative -hlcursor } # Set relative line numbers and visual line break hook global BufWritePost "%val{config}/kakrc" %{ source "%val{config}/kakrc" } # Source kakrc on save hook global BufOpenFile '.*\.clj' %{ terminal dash -c "cd $(dirname $kak_buffile); lein repl" } # Set defaults for clojure coding hook global BufWritePost "%val{config}/autoload/colorscheme.kak" %{ source "%val{config}/autoload/colorscheme.kak" evaluate-commands palette-gutter } # Automatically source colorscheme.kak on save hook global BufOpenFile "%val{config}/autoload/colorscheme.kak" %{ evaluate-commands palette-gutter } # Display faces in the colorscheme file hook global BufOpenFile .* %{ add-highlighter buffer/ wrap -indent -word -marker '↩' add-highlighter buffer/ show-whitespaces -tab '→' } # Set highlighters for file buffers hook global BufCreate '\*scratch\*' %{ add-highlighter buffer/ wrap -indent -word -marker '↩' add-highlighter buffer/ show-whitespaces -tab '→' } # Set highlighters for scratch buffers hook global InsertCompletionShow .* %{ map window insert map window insert } hook global InsertCompletionHide .* %{ map window insert map window insert } # Use tab for completion movement hook global BufWritePost ".*[.](tex)" %{ evaluate-commands texlab-build } # Build tex-projects on save hook -group config global BufSetOption filetype=kak %{ set-option buffer indentwidth 2 set-option buffer line_comment_token '#' } # Kakscript comment tokens hook -group config global BufSetOption filetype=scheme %{ #map buffer normal '' ': echo %sh{ guile -c "(display $kak_reg_dot)" }' set-option buffer indentwidth 2 set-option buffer line_comment_token ';;' set-option buffer block_comment_tokens '#|' '|#' evaluate-commands 'rainbow-enable' } # Guile Scheme hook -group config global BufSetOption filetype=clojure %{ set-option buffer indentwidth 2 set-option window formatcmd 'zprint' set-option window lintcmd 'clj-kondo' set-option buffer line_comment_t set-option buffer block_comment_tokens '(comment' ')' evaluate-commands 'rainbow-enable' } # Clojure comment tokens hook -group config global BufSetOption filetype=(c|cpp) %{ set-option window formatcmd 'clazy' set-option buffer line_comment_token '//' set-option buffer block_comment_tokens '/*' '*/' } # C and C++ comment tokens hook -group config global BufSetOption filetype=python %{ set-option buffer line_comment_token '#' set-option buffer block_comment_tokens '"""' '"""' } # Python comment token tokens hook -group config global BufSetOption filetype=lua %{ set-option buffer line_comment_token '--' set-option buffer block_comment_tokens '[[--' '--]]' } # Lua comment tokens hook -group config global BufSetOption filetype=(sh|dash) %{ set-option window formatcmd 'shfmt' set-option window lintcmd 'shellharden' set-option buffer line_comment_token '#' set-option buffer block_comment_tokens "<<'####'" '###' } # Shell comment tokens hook -group config global BufSetOption filetype=zig %{ set-option buffer line_comment_token '//' } # Zig comment tokens #hook global BufWritePre "/home/radio/Projects/Markdown/latim-portugues.md" %{ # execute-keys '"aZ' # Save registers # execute-keys '%s`[a-zA-ZâêîôûãẽĩõũÂÊÎÔÛÃẼĨÕŨ]+`' # Select latin text # evaluate-commands 'parse-latin' # Mark properly longs and shorts # execute-keys '"az' # Restore registers # evaluate-commands 'echo' #} # Use proper signaling for longs and shorts in latin hook global BufOpenFile "/home/radio/Projects/markdown/latim-portugues.md" %{ hook buffer InsertKey '' %{ execute-keys '"bZ' # Save registers execute-keys 'kx' # Select entered line execute-keys 's`[a-zA-Z ,âêîôûãẽĩõũÂÊÎÔÛÃẼĨÕŨ]+`' # Select latin text evaluate-commands 'parse-latin' # Mark properly longs and shorts execute-keys '|par' # Format line properly execute-keys '"bzi' # Restore registers and return to insert mode evaluate-commands 'echo' } } hook global WinSetOption filetype=kak %{ hook global NormalIdle .* %{ evaluate-commands -save-regs 'a' %{ try %{ execute-keys -draft w"ay evaluate-commands %sh{ ( color="${kak_reg_a}" inverted_color=$(echo "${color}" | perl -pe 'tr/0123456789abcdefABCDEF/fedcba9876543210543210/') printf "%s\n" "evaluate-commands -client $kak_client %{ try %{ echo -markup %{{rgb:${inverted_color},rgb:${color}+b} #${color} } }}" | kak -p $kak_session ) >/dev/null 2>&1 ' # -docstring 'auto-percent s' # map global selectors 'p' ': if-cursor S S' # -docstring 'auto-percent S' # map global selectors '' ': if-cursor a-s> a-s> no-hooks' # -docstring 'auto-percent ' # map global selectors 'm' ': if-cursor a-S> a-S> no-hooks' # -docstring 'auto-percent ' # map global selectors 'f' ': if-cursor a-s>a-k> a-k>' # -docstring 'auto-percent ' # map global selectors 'r' ': if-cursor a-s>a-K> a-K>' # -docstring 'auto-percent ' # map global selectors 'v' ': select-view' # -docstring 'select view' # map global normal s ': enter-user-mode selectors' # -docstring 'selectors' #} # Add text objects to kakoune # __________ LSP __________ hook global BufSetOption filetype=(c|clojure|cpp|crystal|css|haskell|html|js|json|lua|python|scheme|sh|sql|latex|zig) %{ add-highlighter buffer/ column 80 StatusLine } hook global BufSetOption filetype=(c|clojure|cpp|crystal|css|haskell|html|js|json|lua|python|sh|latex|zig) %{ evaluate-commands lsp-enable } # Latex set-option -add global lsp_server_configuration texlab.build.onSave=true set-option -add global lsp_server_configuration texlab.build.forwardSearchAfter=true set-option -add global lsp_server_configuration texlab.build.args=["-pdf","-new-viewer-","-pdflatex\=pdflatex","-silent","-shell-escape","%f"]