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

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