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

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