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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. # Manually merge and source plugins
  2. eval %sh{
  3. kaksource "$kak_config/autosource"
  4. kak-lsp --kakoune -s $kak_session
  5. colorcol
  6. }
  7. # Initialization
  8. decl -hidden regex curword
  9. set global ui_options ncurses_assistant=none
  10. set global scrolloff 7,7
  11. set global autoreload yes
  12. set global kitty_window_type kitty
  13. set global grepcmd 'rg -iHL --column'
  14. set global modelinefmt '%opt{modeline_git_branch} %val{bufname}
  15. %val{cursor_line}:%val{cursor_char_column} {{mode_info}}
  16. {{context_info}}◂%val{client}⊙%val{session}▸'
  17. set global connect_source "%val{config}/autosource/splug"
  18. set global connect_shell elvish
  19. set global fzf_implementation sk
  20. set global fzf_file_command fd
  21. set global fzf_highlight_cmd bat
  22. set global fzf_sk_grep_command 'rg -LHn'
  23. unalias global e edit
  24. alias global e edit-or-dir
  25. alias global bd delete-buffer
  26. alias global bf buffer-first
  27. alias global bl buffer-last
  28. alias global bo buffer-only
  29. alias global bo! buffer-only-force
  30. alias global sw sudo-write
  31. alias global cdb change-directory-current-buffer
  32. alias global f find
  33. alias global c connect-terminal
  34. face global LineNumbersWrapped black
  35. addhl global/ number-lines -hlcursor -separator ' '
  36. addhl global/ column 80 default,rgb:303030
  37. addhl global/ regex '\h+$' 0:default,red
  38. addhl global/ regex \b(TODO|FIXME|XXX|NOTE)\b 0:default+rb
  39. addhl global/ show-matching
  40. addhl global/ wrap -word -indent -marker ''
  41. addhl global/ dynregex '%opt{curword}' 0:+b
  42. # Keybinds
  43. map global normal <space> ,
  44. map global normal -docstring 'remove all sels except main' <backspace> <space>
  45. map global normal -docstring 'remove main sel' <a-backspace> <a-space>
  46. map global normal -docstring 'comment line' '#' ': comment-line<ret>'
  47. map global normal -docstring 'comment block' '<a-#>' ': comment-block<ret>'
  48. map global normal -docstring 'delete to end of line' D <a-l>d
  49. map global normal -docstring 'yank to end of line' Y <a-l>
  50. map global user -docstring 'add phantom selection' f ': phantom-sel-add-selection<ret>'
  51. map global user -docstring 'clear all phantom selections' <a-f> ': phantom-sel-select-all<ret>: phantom-sel-clear<ret>'
  52. map global user -docstring 'next phantom selection' F ': phantom-sel-iterate-next<ret>'
  53. map global user -docstring 'previous phantom selection' <a-F> ': phantom-sel-iterate-prev<ret>'
  54. map global normal -docstring 'select view' <a-%> ': select-view<ret>'
  55. map global view -docstring 'select view' s '<esc>: select-view<ret>'
  56. map global user -docstring 'select selection on each line' s ': keep-selection-each-line<ret>'
  57. map global user -docstring 'drop selection on each line' S ': drop-selection-each-line<ret>'
  58. map global user -docstring 'add mark' m ': mark-word<ret>'
  59. map global user -docstring 'clear marks' M ': mark-clear<ret>'
  60. map global user -docstring 'replace mode' r ': replace<ret>'
  61. map global normal <a-space> ': fzf-mode<ret>'
  62. map global user -docstring 'expand selection' e ': expand<ret>'
  63. map global user -docstring 'expand repeat' E ': expand-repeat<ret>'
  64. map global user -docstring 'buffers…' b ': enter-buffers-mode<ret>'
  65. map global user -docstring 'buffers (lock)…' B ': enter-user-mode -lock buffers<ret>'
  66. map global user -docstring "next error" l ': lint-next-error<ret>'
  67. map global user -docstring "previous error" L ': lint-previous-error<ret>'
  68. declare-user-mode surround
  69. map global user -docstring 'surround mode' <a-s> ': enter-user-mode surround<ret>'
  70. map global surround -docstring 'surround' s ': surround<ret>'
  71. map global surround -docstring 'change' c ': change-surround<ret>'
  72. map global surround -docstring 'delete' d ': delete-surround<ret>'
  73. map global surround -docstring 'select tag' t ': select-surrounding-tag<ret>'
  74. map global surround -docstring 'auto-pairs surround' a ': auto-pairs-surround<ret>'
  75. declare-user-mode anchor
  76. map global normal ';' ': enter-user-mode anchor<ret>'
  77. map global anchor -docstring 'reduce to anchor' a '<a-;>;'
  78. map global anchor -docstring 'reduce to cursor' c ';'
  79. map global anchor -docstring 'flip cursor and anchor' f '<a-;>'
  80. map global anchor -docstring 'ensure anchor after cursor' h '<a-:><a-;>'
  81. map global anchor -docstring 'ensure cursor after anchor' l '<a-:>'
  82. map global anchor -docstring 'select cursor and anchor' s '<a-S>'
  83. declare-user-mode clipboard
  84. map global normal ',' ': enter-user-mode clipboard<ret>'
  85. map global clipboard -docstring 'clip-paste after' p '<a-!>xsel -b -o<ret>'
  86. map global clipboard -docstring 'clip-paste before' P '!xsel -b -o<ret>'
  87. map global clipboard -docstring 'clip-paste replace' R '|xsel -b -o<ret>'
  88. map global clipboard -docstring 'clip-yank' y '<a-|>xclip -i -f -sel c<ret>'
  89. map global clipboard -docstring 'clip-cut -> insert mode' c '<a-|>xclip -i -f -sel c<ret><a-c>'
  90. # Functions
  91. def toggle-highlighter -params .. -docstring 'Toggle highlighter' %{
  92. try %{
  93. addhl window/%arg{@} %arg{@}
  94. echo -markup {green} %arg{@}
  95. } catch %{
  96. rmhl window/%arg{@}
  97. echo -markup {red} %arg{@}
  98. }
  99. }
  100. def lint-on-write -docstring 'Activate linting on buffer write' %{
  101. lint-enable
  102. hook buffer BufWritePost .* lint
  103. }
  104. def format-on-write -docstring 'Format buffer on write' %{
  105. hook buffer BufWritePost .* format
  106. }
  107. def lsp-engage -docstring 'Enable language server' %{
  108. lsp-enable
  109. lsp-auto-hover-enable
  110. map global user -docstring 'Enter lsp user mode' l ': enter-user-mode lsp<ret>'
  111. map global user -docstring 'Lock lsp user mode' L ': enter-user-mode -lock lsp<ret>'
  112. }
  113. def no-tabs -params 0..1 -docstring 'Indent with spaces' %{
  114. eval %sh{ [ -n "$1" ] && printf %s "
  115. set buffer indentwidth $1
  116. set buffer tabstop $1
  117. set buffer softtabstop $1
  118. " }
  119. expandtab
  120. hook buffer InsertKey <space> %{ try %{
  121. exec -draft h<a-i><space><a-k>^\h+<ret>
  122. exec -with-hooks <tab>
  123. } }
  124. }
  125. def clean-trailing-whitespace -docstring 'Remove trailing whitespace' %{
  126. try %{ exec -draft '%s\h+$<ret>d' }
  127. }
  128. # Hooks
  129. hook global WinDisplay .* info-buffers
  130. hook global NormalIdle .* %{ try %{ exec -draft '<a-i>w: palette-status<ret>' } }
  131. hook global BufWritePost .* %{ git show-diff }
  132. hook global BufReload .* %{ git show-diff }
  133. hook global WinCreate .* %{
  134. auto-pairs-enable
  135. search-highlighter-enable
  136. colorcol-enable
  137. colorcol-auto-refresh
  138. discord-presence-enable
  139. }
  140. hook global BufWritePre .* %{ nop %sh{
  141. mkdir -p "$(dirname "$kak_buffile")"
  142. }}
  143. hook global NormalIdle .* %{
  144. eval -draft %{ try %{
  145. exec <space><a-i>w <a-k>\A\w+\z<ret>
  146. set buffer curword "\b\Q%val{selection}\E\b"
  147. } catch %{
  148. set buffer curword ''
  149. } }
  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 window/java }
  159. hook global BufCreate .*\.rasi %{ set buffer filetype css }
  160. # Filetype settings
  161. hook global WinSetOption filetype=sh %{
  162. set buffer lintcmd 'shellcheck -x -fgcc'
  163. lint-on-write
  164. }
  165. hook global WinSetOption filetype=elvish %{
  166. no-tabs 2
  167. }
  168. hook global WinSetOption filetype=(go|rust|python) %{
  169. lsp-engage
  170. set global lsp_server_configuration pyls.plugins.jedi_completion.include_params=false
  171. }
  172. hook global WinSetOption filetype=nim %{
  173. set buffer gdb_program 'nim-gdb'
  174. set buffer formatcmd "nimpretty ${kak_buffile}"
  175. set buffer makecmd 'nimble build'
  176. # 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\"'"
  177. # set buffer lintcmd "sh -c 'nim --stdout --hints:off check $0 | sed \'s/(/:/;s/, /:/;s/)/:/\''"
  178. # lint-on-write
  179. # format-on-write
  180. no-tabs 2
  181. }