summaryrefslogtreecommitdiff
path: root/config/kak/kakrc
diff options
context:
space:
mode:
Diffstat (limited to 'config/kak/kakrc')
-rw-r--r--config/kak/kakrc281
1 files changed, 281 insertions, 0 deletions
diff --git a/config/kak/kakrc b/config/kak/kakrc
new file mode 100644
index 0000000..6966eec
--- /dev/null
+++ b/config/kak/kakrc
@@ -0,0 +1,281 @@
+# --- 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 <tab> <c-n>
+ map window insert <s-tab> <c-p>
+}
+
+hook global InsertCompletionHide .* %{
+ unmap window insert <tab> <c-n>
+ unmap window insert <s-tab> <c-p>
+}
+
+# --- 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 '<esc>:prompt -menu -shell-script-candidates %{ fd -t f } fd: %{ edit %val{text} }<ret>' -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<ret>' -docstring "LSP Format"
+map global user w '|fmt <ret>' -docstring "Wrap to 80 columns"
+map global user l %{:enter-user-mode lsp<ret>} -docstring "LSP mode"
+map global insert <tab> '<a-;>:try lsp-snippets-select-next-placeholders catch %{ execute-keys -with-hooks <lt>tab> }<ret>' -docstring 'Select next snippet placeholder'
+map global object a '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
+map global object <a-a> '<a-semicolon>lsp-object<ret>' -docstring 'LSP any symbol'
+map global object e '<a-semicolon>lsp-object Function Method<ret>' -docstring 'LSP function or method'
+map global object k '<a-semicolon>lsp-object Class Interface Struct<ret>' -docstring 'LSP class interface or struct'
+map global object d '<a-semicolon>lsp-diagnostic-object --include-warnings<ret>' -docstring 'LSP errors and warnings'
+map global object D '<a-semicolon>lsp-diagnostic-object<ret>' -docstring 'LSP errors'
+map global object h '<a-semicolon>lsp-diagnostic-object<ret>' -docstring 'LSP errors'
+map global user k ':lsp-hover<ret>' -docstring 'LSP errors'
+map global normal \' ":"
+map global insert <a-k> "<a-;>:lsp-signature-help<ret>"
+map global user m ':make<ret>' -docstring "Run make"
+
+# --- Hunks
+declare-user-mode hunk
+
+
+map global hunk s ':git apply --cached<ret>:git update-diff<ret>' -docstring 'Stage hunk at cursor'
+map global hunk r ':git apply --reverse<ret>:git update-diff<ret>' -docstring 'Remove hunk at cursor'
+map global hunk ] ':git next-hunk<ret>' -docstring 'Git hunk next'
+map global hunk [ ':git prev-hunk<ret>' -docstring 'Git hunk prev'
+map -docstring 'Goto hunk' global user h ': enter-user-mode hunk<ret>'
+
+# --- Surround
+
+declare-user-mode surround
+
+define-command declare-surrounding-pair -params 4 -docstring 'declare-surrounding-pair <description> <alias> <opening> <closing>: declare surrounding pair' %{
+ map -docstring %arg{1} global surround %arg{2} "Z\i%arg{3}<esc>\a%arg{4}<esc>Hz"
+ map -docstring %arg{1} global surround %arg{3} "Z\i%arg{3}<esc>\a%arg{4}<esc>Hz"
+ map -docstring %arg{1} global surround %arg{4} "Z\i%arg{3}<esc>\a%arg{4}<esc>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 <lt> <gt>
+
+map -docstring 'enter surround mode' global user c ': enter-user-mode surround<ret>'
+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<ret>'
+
+map global object m %{c^[<lt>=]{4\,}[^\n]*\n,^[<gt>=]{4\,}[^\n]*\n<ret>} -docstring 'conflict markers'
+define-command conflict-use-1 %{
+ evaluate-commands -draft %{
+ execute-keys <a-h>h/^<lt>{4}<ret><a-x>d
+ execute-keys h/^={4}<ret>j
+ execute-keys -with-maps <a-a>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 <a-a>m
+ execute-keys dh/^>{4}<ret><a-x>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 '<a-|>tee /tmp/ocaml-rapper.txt;ocaml-rapper-helper /tmp/ocaml-rapper.txt<ret>'
+}
+
+
+# --- SNIPPETS
+
+map global insert <a-f> "<esc>: phantom-selection-iterate-next<ret>i"
+map global insert <a-F> "<esc>: phantom-selection-iterate-prev<ret>i"
+map global user f ":phantom-selection-select-all; phantom-selection-clear<ret>,"
+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
+