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 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. # External plugins
  2. eval %sh{
  3. kak-lsp --kakoune -s $kak_session
  4. colorcol
  5. indentguide
  6. }
  7. # Initialization
  8. require-module search-highlighter
  9. require-module word-select
  10. require-module replace-mode
  11. require-module fandt
  12. set global ui_options ncurses_assistant=none
  13. set global scrolloff 7,7
  14. set global autoreload yes
  15. set global grepcmd 'rg -iHL --column'
  16. set global modelinefmt '%opt{git_branch_str}%val{bufname}
  17. %val{cursor_line}:%val{cursor_char_column} {{mode_info}}
  18. {{context_info}}◂%val{client}⊙%val{session}▸'
  19. alias global sw sudo-write
  20. alias global cdb change-directory-current-buffer
  21. alias global f find
  22. alias global g grep
  23. face global LineNumbersWrapped black
  24. # Keybinds
  25. map global normal <space> ,
  26. map global normal -docstring 'remove all sels except main' <backspace> <space>
  27. map global normal -docstring 'remove main sel' <a-backspace> <a-space>
  28. map global normal -docstring 'comment line' '#' ': comment-line<ret>'
  29. map global normal -docstring 'comment block' '<a-#>' ': comment-block<ret>'
  30. map global normal -docstring 'delete to end of line' D <a-l>d
  31. map global normal -docstring 'yank to end of line' Y <a-l>
  32. map global normal -docstring 'replay macro' , q
  33. map global normal -docstring 'record macro' <a-,> Q
  34. map global normal w ': word-select-next-word<ret>'
  35. map global normal <a-w> ': word-select-next-big-word<ret>'
  36. map global normal q ': word-select-previous-word<ret>'
  37. map global normal <a-q> ': word-select-previous-big-word<ret>'
  38. map global normal Q B
  39. map global normal <a-Q> <a-B>
  40. map global user -docstring 'replace mode' <a-r> ': enter-replace-mode<ret>'
  41. map global user -docstring 'change directory' <a-c> ': enter-user-mode cd<ret>'
  42. map global user -docstring 'expand selection' e ': expand<ret>'
  43. map global user -docstring 'expand repeat' E ': expand-repeat<ret>'
  44. map global normal -docstring 'buffers…' b ': enter-buffers-mode<ret>'
  45. map global normal -docstring 'buffers (lock)…' <a-b> ': enter-user-mode -lock buffers<ret>'
  46. map global normal -docstring 'buffer switcher' B ': buffer-switcher<ret>'
  47. declare-user-mode anchor
  48. map global normal ';' ': enter-user-mode anchor<ret>'
  49. map global anchor -docstring 'ensure anchor after cursor' h '<a-:><a-;>'
  50. map global anchor -docstring 'ensure cursor after anchor' l '<a-:>'
  51. map global anchor -docstring 'flip cursor and anchor' f '<a-;>'
  52. map global anchor -docstring 'reduce to anchor' a '<a-;>;'
  53. map global anchor -docstring 'reduce to cursor' c ';'
  54. map global anchor -docstring 'select cursor and anchor' s '<a-S>'
  55. map global user -docstring 'clip-paste after' p '<a-!>xsel -b -o<ret>'
  56. map global user -docstring 'clip-paste before' P '!xsel -b -o<ret>'
  57. map global user -docstring 'clip-paste replace' R '|xsel -b -o<ret>'
  58. map global user -docstring 'clip-yank' y '<a-|>xclip -i -f -sel c<ret>'
  59. map global user -docstring 'clip-cut' d '<a-|>xclip -i -f -sel c<ret><a-d>'
  60. map global user -docstring 'clip-cut -> insert mode' c '<a-|>xclip -i -f -sel c<ret><a-c>'
  61. # Functions
  62. def type -params 1 -docstring 'Set buffer filetype' %{
  63. set buffer filetype %arg{1}
  64. }
  65. def lint-engage -docstring 'Enable linting' %{
  66. lint-enable
  67. map buffer user -docstring "next error" l ': lint-next-error<ret>'
  68. map buffer user -docstring "previous error" L ': lint-previous-error<ret>'
  69. }
  70. def lsp-engage -docstring 'Enable language server' %{
  71. lsp-enable
  72. lsp-auto-hover-enable
  73. map buffer user -docstring 'Enter lsp user mode' <a-l> ': enter-user-mode lsp<ret>'
  74. }
  75. def lsp-semantic-highlighting -docstring 'Enable semantic highlighting' %{
  76. hook window -group semantic-tokens BufReload .* lsp-semantic-tokens
  77. hook window -group semantic-tokens NormalIdle .* lsp-semantic-tokens
  78. hook window -group semantic-tokens InsertIdle .* lsp-semantic-tokens
  79. hook -once -always window WinSetOption filetype=.* %{
  80. remove-hooks window semantic-tokens
  81. }
  82. }
  83. def lint-on-write -docstring 'Activate linting on buffer write' %{
  84. lint-engage
  85. hook buffer BufWritePost .* lint
  86. }
  87. def set-indent -params 1 -docstring 'Set indentation width' %{
  88. set buffer indentwidth %arg{1}
  89. set buffer tabstop %arg{1}
  90. set buffer softtabstop %arg{1}
  91. }
  92. def no-tabs -params 1 -docstring 'Indent with spaces' %{
  93. expandtab
  94. set-indent %arg{1}
  95. hook buffer InsertKey <space> %{ try %{
  96. exec -draft h<a-i><space><a-k>^\h+<ret>
  97. exec -with-hooks <tab>
  98. }}
  99. }
  100. def clean-trailing-whitespace -docstring 'Remove trailing whitespace' %{
  101. try %{ exec -draft '%s\h+$<ret>d' }
  102. }
  103. def -hidden -docstring \
  104. 'select a word under cursor, or add cursor on next occurrence of current selection' \
  105. select-or-add-cursor %{
  106. try %{
  107. exec "<a-k>\A.\z<ret>"
  108. exec -save-regs '' "_<a-i>w*"
  109. } catch %{
  110. exec -save-regs '' "_*<s-n>"
  111. } catch nop
  112. }
  113. # Hooks
  114. hook global WinCreate .* %{
  115. addhl buffer/number-lines number-lines -hlcursor -separator ' '
  116. addhl buffer/ruler column 100 default,rgb:303030
  117. addhl buffer/trailing-whitespace regex '\h+$' 0:default,red
  118. addhl buffer/todo regex \b(TODO|FIXME|XXX|NOTE)\b 0:default+rb
  119. addhl buffer/matching-brackets show-matching
  120. addhl buffer/wrap wrap -word -indent -marker ''
  121. smarttab
  122. readline-enable
  123. colorcol-enable
  124. colorcol-refresh-continuous
  125. indentguide-enable
  126. indentguide-refresh-continuous
  127. mark-show-enable
  128. hook window NormalIdle .* refresh-git-branch
  129. }
  130. hook global KakBegin .* %{
  131. state-save-reg-load colon
  132. state-save-reg-load pipe
  133. state-save-reg-load slash
  134. }
  135. hook global KakEnd .* %{
  136. state-save-reg-save colon
  137. state-save-reg-save pipe
  138. state-save-reg-save slash
  139. }
  140. hook global WinDisplay .* info-buffers
  141. hook global BufWritePre .* %{ nop %sh{
  142. mkdir -p "$(dirname "$kak_buffile")"
  143. }}
  144. eval %sh{ git rev-parse --is-inside-work-tree 2>/dev/null 1>/dev/null && printf %s "
  145. hook global BufWritePost .* %{ git show-diff }
  146. hook global BufReload .* %{ git show-diff }
  147. "}
  148. hook global ModuleLoaded kitty %{
  149. set global kitty_window_type kitty
  150. }
  151. # Filetype detection
  152. hook global BufCreate .*srcpkgs/.+/template$ %{
  153. set buffer filetype sh
  154. def xgensum %{ %sh{ xgensum -i "$kak_buffile" } }
  155. }
  156. hook global BufCreate .*/\.?((sx|xinit)(rc)?|profile) %{ set buffer filetype sh }
  157. hook global BufCreate .*\.ino %{ set buffer filetype cpp }
  158. hook global BufCreate .*\.cs %{ addhl buffer/java ref java }
  159. hook global BufCreate .*\.rasi %{ set buffer filetype css }
  160. hook global BufCreate .*\.sccprofile %{ set buffer filetype json }
  161. # Filetype settings
  162. hook global WinSetOption filetype=kak %{
  163. no-tabs 2
  164. }
  165. hook global WinSetOption filetype=sh %{
  166. set buffer lintcmd 'shellcheck --norc -x -f gcc'
  167. lint-on-write
  168. }
  169. hook global WinSetOption filetype=elvish %{
  170. no-tabs 2
  171. }
  172. hook global WinSetOption filetype=go %{
  173. lsp-engage
  174. }
  175. hook global WinSetOption filetype=(c|cpp) %{
  176. set buffer formatcmd clang-format
  177. lsp-engage
  178. }
  179. hook global WinSetOption filetype=rust %{
  180. hook window -group rust-inlay-hints BufReload .* rust-analyzer-inlay-hints
  181. hook window -group rust-inlay-hints NormalIdle .* rust-analyzer-inlay-hints
  182. hook window -group rust-inlay-hints InsertIdle .* rust-analyzer-inlay-hints
  183. hook -once -always window WinSetOption filetype=.* %{
  184. remove-hooks window rust-inlay-hints
  185. }
  186. lsp-engage
  187. }
  188. hook global WinSetOption filetype=markdown %{
  189. set buffer formatcmd 'prettier --parser markdown'
  190. }
  191. hook global WinSetOption filetype=python %{
  192. set global lsp_server_configuration pyls.plugins.jedi_completion.include_params=false
  193. lsp-engage
  194. }
  195. hook global WinSetOption filetype=nim %{
  196. set buffer gdb_program 'nim-gdb'
  197. set buffer formatcmd 'nimprettify'
  198. no-tabs 2
  199. lsp-engage
  200. }