# Clipboard (wayland) integration
+# ──────────────────────────────────────────────────────────────────────────────
hook global NormalKey y %{ nop %sh{
printf %s "$kak_main_reg_dquote" | wl-copy > /dev/null 2>&1 &
}}
-# Kakoune shell integration, see https://github.com/kkga/kks
-eval %sh{ kks init }
-
# Enable PLUGin manager
-# ─────────────────────
+# ──────────────────────────────────────────────────────────────────────────────
source "%val{config}/plugins/plug.kak/rc/plug.kak"
plug "andreyorst/plug.kak" noload
plug "Ersikan/bookmarks.kak" %{
hook global WinSetOption filetype=(c|cpp) smarttab
}
plug "whereswaldon/shellcheck.kak"
- plug "kakounedotcom/prelude.kak"
+ plug "occivink/kakoune-filetree"
plug "occivink/kakoune-sudo-write"
plug "occivink/kakoune-find"
plug "foot.kak"
plug "https://git.sr.ht/~nasmevka/dabruin.kak"
- plug "https://github.com/enricozb/tabs.kak"
+ plug "andreyorst/powerline.kak" defer powerline_freerunner %{
+ powerline-format global 'mode_info git bufname session client line_column position '
+ powerline-theme freerunner
+ powerline-separator triangle
+ } config %{
+ powerline-start
+ }
+ plug "raiguard/kak-harpoon" %{
+ hook global WinCreate .* harpoon-add-bindings
+ }
-# Look and Feel
-# ─────────────
-set-option global tabs_modelinefmt '%val{cursor_line}:%val{cursor_char_column} {{mode_info}} '
-set-option global tabs_options --minified
+# Look and Feel
+# ──────────────────────────────────────────────────────────────────────────────
add-highlighter global/trailing-whitespace regex '\h+$' 0:Error # trailing whitespaces in red
add-highlighter global/todos regex '(//|#|/\*)\h*(TODO|WARNING|FIXME)[:]?[^\n]*' 2:+bu # highlight comment tags
add-highlighter global/ show-matching # show matching brackets
set-option global tabstop 4
set-option global indentwidth 4
+
# dynamic scrolloff
-# ─────────────────
+# ──────────────────────────────────────────────────────────────────────────────
hook global WinCreate [^*].* %{
hook -once window WinDisplay .* %{
hook window WinResize [0-9]*\.[0-9]* %{
}
}
+
# Different Cursor color in insert mode
-# ─────────────────────────────────────
+# ──────────────────────────────────────────────────────────────────────────────
# Shades of blue/cyan for normal mode
set-face global PrimarySelection white,blue+F
set-face global SecondarySelection black,blue+F
# Shades of green/yellow for insert mode.
hook global ModeChange (push|pop):.*:insert %{
- set-face window PrimarySelection white,green+F
- set-face window SecondarySelection black,green+F
- set-face window PrimaryCursor black,bright-yellow+F
- set-face window SecondaryCursor black,bright-green+F
- set-face window PrimaryCursorEol black,bright-yellow
- set-face window SecondaryCursorEol black,bright-green
+ set-face window PrimarySelection black,yellow+F
+ set-face window SecondarySelection black,yellow+F
+ set-face window PrimaryCursor black,bright-red+F
+ set-face window SecondaryCursor black,bright-yellow+F
+ set-face window PrimaryCursorEol black,bright-red
+ set-face window SecondaryCursorEol black,bright-yellow
}
# Undo colour changes when we leave insert mode.
unset-face window SecondaryCursorEol
}
+
# Enable editor config
-# ────────────────────
+# ──────────────────────────────────────────────────────────────────────────────
hook global WinCreate ^[^*]+$ %{ editorconfig-load }
+
# Extra editor commands
-# ─────────────────────
+# ──────────────────────────────────────────────────────────────────────────────
# tab replacement
define-command clean-selections -docstring 'Replace tabs with spaces and trim trailing whitespace' %{ try %{
execute-keys -draft @s\h+$<ret>d
# Various mappings
-# ────────────────
+# ──────────────────────────────────────────────────────────────────────────────
map global normal '#' :comment-line<ret> -docstring 'comment line'
map global normal '<a-#>' :comment-block<ret> -docstring 'comment block'
map global goto m '<esc>m;' -docstring 'matching char'
map global normal <c-a> ': inc %val{count} +<ret>'
map global normal <c-x> ': inc %val{count} -<ret>'
map global normal Q q # map q to Q
-map global normal q -docstring 'tabs mode' ': enter-user-mode tabs<ret>' # map q to tabs mode
+#map global normal q -docstring 'tabs mode' ': enter-user-mode tabs<ret>' # map q to tabs mode
+
# default user mode
-# # ──────────
+# ──────────────────────────────────────────────────────────────────────────────
map global user -docstring 'enable autocomplete' a ': set-option -add buffer autocomplete insert<ret>'
map global user -docstring 'disable autocomplete' A ': set-option -remove buffer autocomplete insert<ret>'
map global user -docstring 'edit kakrc' e ': e ~/.config/kak/kakrc<ret>'
map global user -docstring 'wrap enable' w ': add-highlighter buffer/bw wrap<ret>'
map global user -docstring 'wrap disable' W ': remove-highlighter buffer/bw<ret>'
-# tabs user mode
-# # ──────────
-map global normal <c-p> -docstring 'kks mode' ': enter-user-mode kks<ret>'
-
-
-# kks user mode
-# # ──────────
-declare-user-mode kks
-map global normal <c-p> -docstring 'kks mode' ': enter-user-mode kks<ret>'
-map global kks f -docstring 'files' ': kks-connect terminal-popup kks-files<ret>'
-map global kks F -docstring 'files (all)' ': kks-connect terminal-popup kks-files -HI<ret>'
-map global kks g -docstring 'git files' ': kks-connect terminal-popup kks-git-files<ret>'
-map global kks b -docstring 'buffers' ': kks-connect terminal-popup kks-buffers<ret>'
-map global kks / -docstring 'live grep' ': kks-connect terminal-popup kks-grep<ret>'
-map global kks l -docstring 'lines in buffer' ': kks-connect terminal-popup kks-lines<ret>'
-map global kks r -docstring 'recent files' ': kks-connect terminal-popup kks-mru<ret>'
-map global kks <a-f> -docstring 'filetypes' ': kks-connect terminal-popup kks-filetypes<ret>'
+# terminal config (via foot.kak)
+# ──────────────────────────────────────────────────────────────────────────────
set-option global foot_normal_cmd 'foot'
set-option global foot_popup_cmd 'foot'
set-option global foot_normal_flags ''
-set-option global foot_popup_flags '-a popup'
+set-option global foot_popup_flags '-a kakpopup'
set-option global foot_panel_cmd 'foot'
-# suspend and resume
-# # ──────────
-def suspend-and-resume \
- -params 1..2 \
- -docstring 'suspend-and-resume <cli command> [<kak command after resume>]: backgrounds current kakoune client and runs specified cli command. Upon exit of command the optional kak command is executed.' \
- %{ evaluate-commands %sh{
-
- # Note we are adding '&& fg' which resumes the kakoune client process after the cli command exits
- cli_cmd="$1 && fg"
- post_resume_cmd="$2"
-
- # automation is different platform to platform
- platform=$(uname -s)
- case $platform in
- Darwin)
- automate_cmd="sleep 0.01; osascript -e 'tell application \"System Events\" to keystroke \"$cli_cmd\" & return '"
- kill_cmd="/bin/kill"
- break
- ;;
- Linux)
- automate_cmd="sleep 0.2; xdotool type '$cli_cmd'; xdotool key Return"
- kill_cmd="/usr/bin/kill"
- break
- ;;
- esac
-
- # Uses platforms automation to schedule the typing of our cli command
- nohup sh -c "$automate_cmd" > /dev/null 2>&1 &
- # Send kakoune client to the background
- $kill_cmd -SIGTSTP $kak_client_pid
-
- # ...At this point the kakoune client is paused until the " && fg " gets run in the $automate_cmd
-
- # Upon resume, run the kak command is specified
- if [ ! -z "$post_resume_cmd" ]; then
- echo "$post_resume_cmd"
- fi
-}}
-def for-each-line \
- -docstring "for-each-line <command> <path to file>: run command with the value of each line in the file" \
- -params 2 \
- %{ evaluate-commands %sh{
+# # suspend and resume
+# # # ──────────
+# def suspend-and-resume \
+# -params 1..2 \
+# -docstring 'suspend-and-resume <cli command> [<kak command after resume>]: backgrounds current kakoune client and runs specified cli command. Upon exit of command the optional kak command is executed.' \
+# %{ evaluate-commands %sh{
- while read f; do
- printf "$1 $f\n"
- done < "$2"
-}}
+# # Note we are adding '&& fg' which resumes the kakoune client process after the cli command exits
+# cli_cmd="$1 && fg"
+# post_resume_cmd="$2"
-def toggle-ranger %{
- suspend-and-resume \
- "ranger --choosefiles=/tmp/ranger-files-%val{client_pid}" \
- "for-each-line edit /tmp/ranger-files-%val{client_pid}"
-}
+# # automation is different platform to platform
+# platform=$(uname -s)
+# case $platform in
+# Darwin)
+# automate_cmd="sleep 0.01; osascript -e 'tell application \"System Events\" to keystroke \"$cli_cmd\" & return '"
+# kill_cmd="/bin/kill"
+# break
+# ;;
+# Linux)
+# automate_cmd="sleep 0.2; xdotool type '$cli_cmd'; xdotool key Return"
+# kill_cmd="/usr/bin/kill"
+# break
+# ;;
+# esac
-map global user f ': toggle-ranger<ret>' -docstring 'select files in ranger'
+# # Uses platforms automation to schedule the typing of our cli command
+# nohup sh -c "$automate_cmd" > /dev/null 2>&1 &
+# # Send kakoune client to the background
+# $kill_cmd -SIGTSTP $kak_client_pid
+
+# # ...At this point the kakoune client is paused until the " && fg " gets run in the $automate_cmd
+
+# # Upon resume, run the kak command is specified
+# if [ ! -z "$post_resume_cmd" ]; then
+# echo "$post_resume_cmd"
+# fi
+# }}
+
+# def for-each-line \
+# -docstring "for-each-line <command> <path to file>: run command with the value of each line in the file" \
+# -params 2 \
+# %{ evaluate-commands %sh{
+
+# while read f; do
+# printf "$1 $f\n"
+# done < "$2"
+# }}
+
+# def toggle-ranger %{
+# suspend-and-resume \
+# "ranger --choosefiles=/tmp/ranger-files-%val{client_pid}" \
+# "for-each-line edit /tmp/ranger-files-%val{client_pid}"
+# }
+
+# map global user f ': toggle-ranger<ret>' -docstring 'select files in ranger'
# run on file open
-# ─────────────
+# ──────────────────────────────────────────────────────────────────────────────
hook global BufOpenFile .* %{
modeline-parse
}
+# session manager
+# ──────────────────────────────────────────────────────────────────────────────
+evaluate-commands %sh{
+ kcr init kakoune
+}
+
+# kakoune.cr Mappings
+map -docstring 'new client' global normal <c-t> ': new<ret>'
+map -docstring 'terminal (popup)' global normal <c-ret> ': connect terminal-popup<ret>'
+map -docstring 'git (popup)' global normal <c-l> ': connect terminal-popup gitui<ret>'
+#map -docstring 'file explorer' global normal <c-e> ': connect terminal-panel sidetree --select %val{buffile}<ret>'
+map -docstring 'file picker' global normal <c-f> ': connect terminal-popup kcr fzf files<ret>'
+map -docstring 'buffer picker' global normal <c-b> ': connect terminal-popup kcr fzf buffers<ret>'
+map global normal <q> <Q>
+unmap global normal <q>
+map -docstring 'buffer picker' global normal <q> ': connect terminal-popup kcr fzf buffers<ret>'
+map -docstring 'grep picker' global normal <c-g> ': connect terminal-popup kcr fzf grep<ret>'
+#map -docstring 'grep picker (buffer)' global normal <c-r> ': connect terminal-popup kcr fzf grep %val{buflist}<ret>'
+
+
+# Reload kakrc and .kak when saving.
+# ──────────────────────────────────────────────────────────────────────────────
+# Adds -override to definitions (unless they seem to be python defs!)
+# Evals provide module directly
+
+def resource -params 1 %{
+ eval %sh{
+ file=$(dirname "$1")/.reload.kak
+ cat "$1" |
+ sed 's/^def \([^:]*\)$/def -override \1/' |
+ sed 's/^define-command /def -override /' |
+ sed 's/^addhl /addhl -override/' |
+ sed 's/^add-highlighter /addhl -override /' |
+ sed 's/^provide-module \w\+ /eval /' |
+ cat > "$file"
+ printf %s "
+ source $file
+ nop %sh{
+ rm $file
+ }
+ "
+ }
+ echo Reloaded %arg{1}
+}
+
+rmhooks global reload-kak
+hook -group reload-kak global BufWritePost (.*kakrc|.*\.kak) %{
+ resource %val{hook_param}
+}