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.2KB

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