You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kakrc 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # Merge and manually source plugins
  2. eval %sh{
  3. cat $(find "$kak_config/autosource" -name '*\.kak') >/tmp/kakmerge.kak
  4. printf %s 'source /tmp/kakmerge.kak'
  5. }
  6. # Initialization
  7. decl -hidden regex curword
  8. set global ui_options ncurses_assistant=none
  9. set global scrolloff 7,7
  10. set global autoreload yes
  11. set global kitty_window_type os
  12. set global termcmd 'kitty -1 sh -c'
  13. set global grepcmd 'rg -iHL --column'
  14. set global filetree_find_cmd 'fd -L -t f -d 2'
  15. set global modelinefmt '%opt{modeline_git_branch} %val{bufname}
  16. %val{cursor_line}:%val{cursor_char_column} {{mode_info}} {{context_info}}
  17. ◂%val{client}⊙%val{session}▸'
  18. unalias global e edit
  19. alias global e edit-or-dir
  20. face global LineNumbersWrapped black
  21. addhl global/ number-lines -hlcursor -separator ' '
  22. addhl global/ column 80 default,rgb:303030
  23. addhl global/ regex '\h+$' 0:default,red
  24. addhl global/ regex \b(TODO|FIXME|XXX|NOTE)\b 0:default+rb
  25. addhl global/ show-matching
  26. addhl global/ wrap -word -indent -marker ↪
  27. addhl global/ dynregex '%reg{/}' 0:+u
  28. addhl global/ dynregex '%opt{curword}' 0:+b
  29. # Keybinds
  30. map global normal <space> ,
  31. map global normal -docstring 'remove all sels except main' <backspace> <space>
  32. map global normal -docstring 'remove main sel' <a-backspace> <a-space>
  33. map global normal -docstring 'comment line' '#' :comment-line<ret>
  34. map global normal -docstring 'comment block' '<a-#>' :comment-block<ret>
  35. map global normal -docstring 'delete to end of line' D <a-l>d
  36. map global normal -docstring 'yank to end of line' Y <a-l>y
  37. map global user -docstring "add phantom selection" f :phantom-sel-add-selection<ret>
  38. map global user -docstring "clear all phantom selections" <a-f> :phantom-sel-select-all<ret>:phantom-sel-clear<ret>
  39. map global user -docstring "next phantom selection" F :phantom-sel-iterate-next<ret>
  40. map global user -docstring "previous phantom selection" <a-F> :phantom-sel-iterate-prev<ret>
  41. map global user -docstring "filetree" t :filetree<ret>
  42. map global user -docstring 'buffers' <ret> :rofi-buffers<ret>
  43. map global normal -docstring 'select view' <a-%> ':select-view<ret>'
  44. map global view -docstring 'select view' s '<esc>:select-view<ret>'
  45. map global user -docstring "add mark" m :mark-word<ret>
  46. map global user -docstring "clear marks" M :mark-clear<ret>
  47. map global user -docstring "expand selection" e :expand<ret>
  48. map global user -docstring "expand repeat" E :expand-repeat<ret>
  49. map global normal <c-p> ':yank-ring-previous<ret>'
  50. map global normal <c-n> ':yank-ring-next<ret>'
  51. map global normal Y ':yank-ring-open<ret>'
  52. declare-user-mode surround
  53. map global user -docstring "surround mode" s ':enter-user-mode surround<ret>'
  54. map global surround -docstring 'surround' s ':surround<ret>'
  55. map global surround -docstring 'change' c ':change-surround<ret>'
  56. map global surround -docstring 'delete' d ':delete-surround<ret>'
  57. map global surround -docstring 'select tag' t ':select-surrounding-tag<ret>'
  58. map global surround -docstring 'auto-pairs surround' a ':auto-pairs-surround<ret>'
  59. declare-user-mode anchor
  60. map global normal ';' ':enter-user-mode anchor<ret>'
  61. map global anchor -docstring 'reduce to anchor' a '<a-;>;'
  62. map global anchor -docstring 'reduce to cursor' c ';'
  63. map global anchor -docstring 'flip cursor and anchor' f '<a-;>'
  64. map global anchor -docstring 'ensure anchor after cursor' h '<a-:><a-;>'
  65. map global anchor -docstring 'ensure cursor after anchor' l '<a-:>'
  66. map global anchor -docstring 'select cursor and anchor' s '<a-S>'
  67. map global user -docstring "clip-paste after" p '<a-!>xsel -b -o<ret>'
  68. map global user -docstring "clip-paste before" P '!xsel -b -o<ret>'
  69. map global user -docstring "clip-paste replace" R '|xsel -b -o<ret>'
  70. map global user -docstring "clip-yank" y '<a-|>xclip -i -f -sel c<ret>'
  71. map global user -docstring "next error" l :lint-next-error<ret>
  72. map global user -docstring "previous error" L :lint-previous-error<ret>
  73. # Functions
  74. def toggle-highlighter -params .. -docstring 'Toggle highlighter' %{
  75. try %{
  76. addhl window/%arg{@} %arg{@}
  77. echo -markup {green} %arg{@}
  78. } catch %{
  79. rmhl window/%arg{@}
  80. echo -markup {red} %arg{@}
  81. }
  82. }
  83. def lint-on-write -docstring 'Activate linting on buffer write' %{
  84. lint-enable
  85. hook buffer BufWritePost .* %{ lint }
  86. }
  87. def rofi-buffers -docstring 'Select an open buffer using Rofi' %{ eval %sh{
  88. BUF=$(eval set -- "$kak_buflist"; for i; do echo "$i"; done\
  89. | rofi -dmenu -no-custom -p 'Select buffer: ')
  90. [ -n "$BUF" ] && echo buffer "$BUF"
  91. } }
  92. def no-tabs -params 0..1 -docstring 'Indent with spaces' %{
  93. eval %sh{ [ -n "$1" ] && printf %s "
  94. set buffer indentwidth $1
  95. set buffer tabstop $1
  96. set buffer softtabstop $1
  97. " }
  98. exec :expandtab<ret>
  99. hook buffer InsertKey <space> %{ try %{
  100. exec -draft h<a-i><space><a-k>^\h+<ret>
  101. exec -with-hooks <tab>
  102. } }
  103. }
  104. def clean-trailing-whitespace -docstring 'Remove trailing whitespace' %{
  105. try %{ exec -draft '%s\h+$<ret>d' }
  106. }
  107. # Hooks
  108. hook global WinCreate ^[^*]+$ %{
  109. auto-pairs-enable
  110. }
  111. hook global BufOpenFile .* %{
  112. change-directory-current-buffer
  113. }
  114. hook global NormalIdle .* %{
  115. try %{ exec -draft '<a-i>w:palette-status<ret>' }
  116. }
  117. hook global BufWritePre .* %{ nop %sh{
  118. mkdir -p "$(dirname "$kak_buffile")"
  119. }}
  120. hook global BufWritePost .* %{ git show-diff }
  121. hook global BufReload .* %{ git show-diff }
  122. hook global NormalIdle .* %{
  123. eval -draft %{ try %{
  124. exec <space><a-i>w <a-k>\A\w+\z<ret>
  125. set buffer curword "\b\Q%val{selection}\E\b"
  126. } catch %{
  127. set buffer curword ''
  128. } }
  129. }
  130. # Filetype detection
  131. hook global BufCreate .*srcpkgs/.+/template$ %{
  132. set buffer filetype sh
  133. def xgensum %{ %sh{ xgensum -i "$kak_buffile" } }
  134. }
  135. hook global BufCreate .*/\.?((sx|xinit)(rc)?|profile) %{ set buffer filetype sh }
  136. hook global BufCreate .*\.ino %{ set buffer filetype cpp }
  137. hook global BufCreate .*\.cs %{ addhl window/java }
  138. # Filetype settings
  139. hook global WinSetOption filetype=sh %{
  140. set buffer lintcmd 'shellcheck -x -fgcc'
  141. lint-on-write
  142. }
  143. hook global WinSetOption filetype=elvish %{
  144. no-tabs 2
  145. }
  146. hook global WinSetOption filetype=nim %{
  147. set buffer gdb_program 'nim-gdb'
  148. no-tabs 2
  149. # set buffer lintcmd "sh -c 'cp -f $0 $0.nim;nim --stdout --colors:off --hints:off --path:$(dirname ${kak_buffile}) check $0 | sed \"s/(/:/;s/, /:/;s/)/:/\" | sed \":a;N;/\n[buf.nim]/!s/\n//;ta;P;D\"'"
  150. # set buffer lintcmd "sh -c 'nim --stdout --hints:off check $0 | sed \'s/(/:/;s/, /:/;s/)/:/\''"
  151. # lint-on-write
  152. }