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.

kak.kak 8.5KB

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