# --- PLUGINS #source "~/.config/kak/smarttab.kak" source "~/.config/kak/palette.kak" source "~/.config/kak/auto-pairs.kak" source "~/.config/kak/snippets.kak" source "~/.config/kak/phantom-selection.kak" # --- Auto pairs enable-auto-pairs # --- Make hook global BufSetOption filetype=(go) %{ set-option buffer makecmd "go build" } # --- LSP & FORMATTING # https://discuss.kakoune.com/t/sane-kak-lsp-config-hook/2019 hook global WinSetOption filetype=(rust|python|nim|go|javascript|typescript|c|cpp|ocaml|haskell|markdown|elixir|nix) %{ set global lsp_hover_anchor true lsp-enable-window lsp-auto-hover-insert-mode-enable } hook global WinSetOption filetype=(eml|markdown|org) %{ spell } hook global BufSetOption filetype=(javascript|typescript|html) %{ set-option buffer formatcmd "prettier --stdin-filepath=%val{buffile}" hook buffer BufWritePre .* %{format} } hook global BufSetOption filetype=(go) %{ set-option global make_error_pattern "^([^:\n]+):(\d+):(?:(\d+):)?" } hook global BufSetOption filetype=(javascript|typescript|elixir|haskell|rust|markdown|c|cpp) %{ lsp-auto-signature-help-enable } hook global BufSetOption filetype=(terraform|ocaml|elixir|nix|go) %{ hook buffer BufWritePre .* %{lsp-formatting-sync} } eval %sh{kak-lsp --kakoune -s $kak_session} lsp-enable # --- GREP set-option global grepcmd 'rg --column' # --- Tab complete hook global InsertCompletionShow .* %{ map window insert map window insert } hook global InsertCompletionHide .* %{ unmap window insert unmap window insert } # --- Line number add-highlighter global/ number-lines -separator ' ' # --- COMMANDS define-command fd -docstring "find files" -params 1 %{ edit %arg{1} } complete-command fd shell-script-candidates %{ fd -t f } map global goto f ':prompt -menu -shell-script-candidates %{ fd -t f } fd: %{ edit %val{text} }' -docstring "Goto file" define-command z -docstring "Change Directory (Z)" -params 1 %{ change-directory %sh{zoxide query $1} } complete-command z shell-script-candidates %{ zoxide query -l } # --- KEYMAPS map global user = ':lsp-formatting' -docstring "LSP Format" map global user w '|fmt ' -docstring "Wrap to 80 columns" map global user l %{:enter-user-mode lsp} -docstring "LSP mode" map global insert ':try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks tab> }' -docstring 'Select next snippet placeholder' map global object a 'lsp-object' -docstring 'LSP any symbol' map global object 'lsp-object' -docstring 'LSP any symbol' map global object e 'lsp-object Function Method' -docstring 'LSP function or method' map global object k 'lsp-object Class Interface Struct' -docstring 'LSP class interface or struct' map global object d 'lsp-diagnostic-object --include-warnings' -docstring 'LSP errors and warnings' map global object D 'lsp-diagnostic-object' -docstring 'LSP errors' map global object h 'lsp-diagnostic-object' -docstring 'LSP errors' map global user k ':lsp-hover' -docstring 'LSP errors' map global normal \' ":" map global insert ":lsp-signature-help" map global user m ':make' -docstring "Run make" # --- Hunks declare-user-mode hunk map global hunk s ':git apply --cached:git update-diff' -docstring 'Stage hunk at cursor' map global hunk r ':git apply --reverse:git update-diff' -docstring 'Remove hunk at cursor' map global hunk ] ':git next-hunk' -docstring 'Git hunk next' map global hunk [ ':git prev-hunk' -docstring 'Git hunk prev' map -docstring 'Goto hunk' global user h ': enter-user-mode hunk' # --- Surround declare-user-mode surround define-command declare-surrounding-pair -params 4 -docstring 'declare-surrounding-pair : declare surrounding pair' %{ map -docstring %arg{1} global surround %arg{2} "Z\i%arg{3}\a%arg{4}Hz" map -docstring %arg{1} global surround %arg{3} "Z\i%arg{3}\a%arg{4}Hz" map -docstring %arg{1} global surround %arg{4} "Z\i%arg{3}\a%arg{4}Hz" } declare-surrounding-pair 'parenthesis block' b ( ) declare-surrounding-pair 'brace block' B { } declare-surrounding-pair 'bracket block' r [ ] declare-surrounding-pair 'stars' * * * declare-surrounding-pair 'quotation' \' \' \' declare-surrounding-pair 'double quotation' \" \" \" declare-surrounding-pair 'angle block' a map -docstring 'enter surround mode' global user c ': enter-user-mode surround' set-option -add global ui_options terminal_padding_char=‏‏‎  set-option -add global ui_options terminal_assistant=off #set-option global autocomplete prompt #set-option global autoinfo onkey # --- Git hook global WinCreate .* %{git show-diff} hook global BufWritePost .* %{git update-diff} declare-user-mode conflict-resolve map -docstring 'enter conflict resolution' global user u ': enter-user-mode conflict-resolve' map global object m %{c^[=]{4\,}[^\n]*\n,^[=]{4\,}[^\n]*\n} -docstring 'conflict markers' define-command conflict-use-1 %{ evaluate-commands -draft %{ execute-keys h/^{4}d execute-keys h/^={4}j execute-keys -with-maps m execute-keys d } } -docstring "resolve a conflict by using the first version" define-command conflict-use-2 %{ evaluate-commands -draft %{ execute-keys j execute-keys -with-maps m execute-keys dh/^>{4}d } } -docstring "resolve a conflict by using the second version" map global conflict-resolve a conflict-use-1 -docstring "resolve conflict using first version" map global conflict-resolve b conflict-use-2 -docstring "resolve conflict using second version" # --- VISUAL colorscheme simple hook global ModeChange (push|pop):insert:.* %{ set-face global PrimaryCursor rgb:FFFFFF,rgb:000000+F } hook global ModeChange (push|pop):.*:insert %{ set-face global PrimaryCursor default,default+Bc } # Width of a tab set-option global tabstop 8 # Indent with 4 spaces set-option global indentwidth 0 # Use spaces instead of tabs #hook global WinCreate .* %{ expandtab } # Enable spelling for markdown hook global WinCreate filetype=(markdown|.org) %{ spell } # Wrap for org and markdown hook global WinCreate filetype=(markdown|.org) %{ autowrap-enable } # Softwrap long lines add-highlighter global/ wrap -word -indent # Show git branch in statusline declare-option -docstring "name of the git branch holding the current buffer" \ str modeline_git_branch hook global WinCreate .* %{ hook window NormalIdle .* %{ evaluate-commands %sh{ branch=$(cd "$(dirname "${kak_buffile}")" && git rev-parse --abbrev-ref HEAD 2>/dev/null) if [ -n "${branch}" ]; then printf 'set window modeline_git_branch %%{%s}' "${branch}" fi } } } hook global WinCreate .* %{ evaluate-commands %sh{ is_work_tree=$(cd "$(dirname "${kak_buffile}")" && git rev-parse --is-inside-work-tree 2>/dev/null) if [ "${is_work_tree}" = 'true' ]; then printf 'set-option window modelinefmt %%{%s}' "%opt{modeline_git_branch} ${kak_opt_modelinefmt}" fi }} hook global RegisterModified '"' %{ nop %sh{ printf %s "$kak_main_reg_dquote" | xsel --input --clipboard }} hook global BufSetOption filetype=(ocaml) %{ map buffer assistant -docstring "Add rapper definitions to selected code" u 'tee /tmp/ocaml-rapper.txt;ocaml-rapper-helper /tmp/ocaml-rapper.txt' } # --- SNIPPETS map global insert ": phantom-selection-iterate-nexti" map global insert ": phantom-selection-iterate-previ" map global user f ":phantom-selection-select-all; phantom-selection-clear," hook global BufSetOption filetype=(go) %{ set buffer snippets %opt{snippets} # keep global snippets (if any) set -add buffer snippets 'err != nil' 'err@' %{ snippets-insert %{if err != nil { ${} } }} } hook global BufSetOption filetype=(ocaml) %{ set buffer snippets %opt{snippets} # keep global snippets (if any) set -add buffer snippets 'Import Html libs' 'imp-h' %{ snippets-insert %{let open Dream_html in let open HTML in } } set -add buffer snippets '[letform-] Create Web Form' 'letform-' \ %{ phantom-selection-clear ; snippets-insert %{let form ~csrf req = match%lwt Dream.form ~csrf req with | `Ok [ ("${}", ${}); ] -> Lwt_result.return (${}) | e -> Lwt_result.fail (`Form e) ${} }; phantom-selection-add-selection ; phantom-selection-iterate-next } set -add buffer snippets '[form-n] Create user form (base)' 'form-n' \ %{ phantom-selection-clear ; snippets-insert %{null [ h3 [] [txt "${}"] ; form [ id "${}"; action "/${}"; method_ `POST ] [ csrf_tag req ; br [] ] ] }; phantom-selection-add-selection ; phantom-selection-iterate-next } set -add buffer snippets '[form-tf] Create user form (text field)' 'form-tf' \ %{phantom-selection-clear ; snippets-insert %{; label [ for_ "${}" ] [ txt "${}" ] ; input [ id "${}"; name "${}"; type_ "text" ] ; br [] }; phantom-selection-add-selection ; phantom-selection-iterate-next } set -add buffer snippets '[form-b] Create user form (submit)' 'form-b' \ %{ snippets-insert %{; button [type_ "submit"] [ txt "${}" ] }; } set -add buffer snippets '[let-e] Expect test' 'let-e' \ %{ phantom-selection-clear ; snippets-insert %{let%expect_test "${}" = Printf.printf ; [%expect {| |}] |> Lwt.return }; phantom-selection-add-selection ; phantom-selection-iterate-next } set -add buffer snippets '[let-c] controller' 'let-c' \ %{ phantom-selection-clear ; snippets-insert %{let controller ?(csrf=true) = User.Session.auth_middleware @@ fun req -> match%lwt logic ~csrf req with | Ok ${} -> ${} | Error e -> Components.Errors.handle log e }; phantom-selection-add-selection ; phantom-selection-iterate-next } } # TAGS