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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # Merge and manually source plugins
  2. eval %sh{ cat $(find "$kak_config/autosource" -name '*\.kak') }
  3. # Initialization
  4. decl -hidden regex curword
  5. set global ui_options ncurses_assistant=none
  6. set global scrolloff 7,7
  7. set global autoreload yes
  8. set global kitty_window_type os
  9. set global termcmd 'kitty -1 sh -c'
  10. set global grepcmd 'rg -iHL --column'
  11. set global filetree_find_cmd 'fd -L -t f -d 2'
  12. set global modelinefmt '%opt{modeline_git_branch} %val{bufname}
  13. %val{cursor_line}:%val{cursor_char_column} {{mode_info}} {{context_info}}
  14. ◂%val{client}⊙%val{session}▸'
  15. unalias global e edit
  16. alias global e edit-or-dir
  17. face global LineNumbersWrapped black
  18. addhl global/ number-lines -hlcursor -separator ' '
  19. addhl global/ column 80 default,rgb:303030
  20. addhl global/ regex '\h+$' 0:default,red
  21. addhl global/ regex \b(TODO|FIXME|XXX|NOTE)\b 0:default+rb
  22. addhl global/ show-matching
  23. addhl global/ wrap -word -indent -marker ''
  24. addhl global/ dynregex '%reg{/}' 0:+u
  25. addhl global/ dynregex '%opt{curword}' 0:+b
  26. # Keybinds
  27. map global normal <space> ,
  28. map global normal -docstring 'remove all sels except main' <backspace> <space>
  29. map global normal -docstring 'remove main sel' <a-backspace> <a-space>
  30. map global normal -docstring 'comment line' '#' ': comment-line<ret>'
  31. map global normal -docstring 'comment block' '<a-#>' ': comment-block<ret>'
  32. map global normal -docstring 'delete to end of line' D <a-l>d
  33. map global normal -docstring 'yank to end of line' Y <a-l>y
  34. map global user -docstring "add phantom selection" f ': phantom-sel-add-selection<ret>'
  35. map global user -docstring "clear all phantom selections" <a-f> ': phantom-sel-select-all<ret>: phantom-sel-clear<ret>'
  36. map global user -docstring "next phantom selection" F ': phantom-sel-iterate-next<ret>'
  37. map global user -docstring "previous phantom selection" <a-F> ': phantom-sel-iterate-prev<ret>'
  38. map global user -docstring 'filetree' t ': filetree<ret>'
  39. map global normal -docstring 'select view' <a-%> ': select-view<ret>'
  40. map global view -docstring 'select view' s '<esc>: select-view<ret>'
  41. map global user -docstring "add mark" m ': mark-word<ret>'
  42. map global user -docstring "clear marks" M ': mark-clear<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 Y ': yank-ring<ret>'
  46. map global normal <c-p> ': yank-ring<ret><c-p>'
  47. map global normal <c-n> ': yank-ring<ret><c-n>'
  48. map global user -docstring 'buffers…' b ': enter-buffers-mode<ret>'
  49. map global user -docstring 'buffers (lock)…' B ': enter-user-mode -lock buffers<ret>'
  50. declare-user-mode surround
  51. map global user -docstring "surround mode" s ': enter-user-mode surround<ret>'
  52. map global surround -docstring 'surround' s ': surround<ret>'
  53. map global surround -docstring 'change' c ': change-surround<ret>'
  54. map global surround -docstring 'delete' d ': delete-surround<ret>'
  55. map global surround -docstring 'select tag' t ': select-surrounding-tag<ret>'
  56. map global surround -docstring 'auto-pairs surround' a ': auto-pairs-surround<ret>'
  57. declare-user-mode anchor
  58. map global normal ';' ': enter-user-mode anchor<ret>'
  59. map global anchor -docstring 'reduce to anchor' a '<a-;>;'
  60. map global anchor -docstring 'reduce to cursor' c ';'
  61. map global anchor -docstring 'flip cursor and anchor' f '<a-;>'
  62. map global anchor -docstring 'ensure anchor after cursor' h '<a-:><a-;>'
  63. map global anchor -docstring 'ensure cursor after anchor' l '<a-:>'
  64. map global anchor -docstring 'select cursor and anchor' s '<a-S>'
  65. map global user -docstring "clip-paste after" p '<a-!>xsel -b -o<ret>'
  66. map global user -docstring "clip-paste before" P '!xsel -b -o<ret>'
  67. map global user -docstring "clip-paste replace" R '|xsel -b -o<ret>'
  68. map global user -docstring "clip-yank" y '<a-|>xclip -i -f -sel c<ret>'
  69. map global user -docstring "next error" l ': lint-next-error<ret>'
  70. map global user -docstring "previous error" L ': lint-previous-error<ret>'
  71. # Functions
  72. def toggle-highlighter -params .. -docstring 'Toggle highlighter' %{
  73. try %{
  74. addhl window/%arg{@} %arg{@}
  75. echo -markup {green} %arg{@}
  76. } catch %{
  77. rmhl window/%arg{@}
  78. echo -markup {red} %arg{@}
  79. }
  80. }
  81. def lint-on-write -docstring 'Activate linting on buffer write' %{
  82. lint-enable
  83. hook buffer BufWritePost .* %{ lint }
  84. }
  85. def no-tabs -params 0..1 -docstring 'Indent with spaces' %{
  86. eval %sh{ [ -n "$1" ] && printf %s "
  87. set buffer indentwidth $1
  88. set buffer tabstop $1
  89. set buffer softtabstop $1
  90. " }
  91. exec :expandtab<ret>
  92. hook buffer InsertKey <space> %{ try %{
  93. exec -draft h<a-i><space><a-k>^\h+<ret>
  94. exec -with-hooks <tab>
  95. } }
  96. }
  97. def clean-trailing-whitespace -docstring 'Remove trailing whitespace' %{
  98. try %{ exec -draft '%s\h+$<ret>d' }
  99. }
  100. # Hooks
  101. hook global WinDisplay .* info-buffers
  102. hook global WinCreate .* auto-pairs-enable
  103. hook global BufOpenFile .* change-directory-current-buffer
  104. hook global NormalIdle .* %{
  105. try %{ exec -draft '<a-i>w: palette-status<ret>' }
  106. }
  107. hook global BufWritePre .* %{ nop %sh{
  108. mkdir -p "$(dirname "$kak_buffile")"
  109. }}
  110. hook global BufWritePost .* %{ git show-diff }
  111. hook global BufReload .* %{ git show-diff }
  112. hook global NormalIdle .* %{
  113. eval -draft %{ try %{
  114. exec <space><a-i>w <a-k>\A\w+\z<ret>
  115. set buffer curword "\b\Q%val{selection}\E\b"
  116. } catch %{
  117. set buffer curword ''
  118. } }
  119. }
  120. # Filetype detection
  121. hook global BufCreate .*srcpkgs/.+/template$ %{
  122. set buffer filetype sh
  123. def xgensum %{ %sh{ xgensum -i "$kak_buffile" } }
  124. }
  125. hook global BufCreate .*/\.?((sx|xinit)(rc)?|profile) %{ set buffer filetype sh }
  126. hook global BufCreate .*\.ino %{ set buffer filetype cpp }
  127. hook global BufCreate .*\.cs %{ addhl window/java }
  128. hook global BufCreate .*\.rasi %{ set buffer filetype css }
  129. # Filetype settings
  130. hook global WinSetOption filetype=sh %{
  131. set buffer lintcmd 'shellcheck -x -fgcc'
  132. lint-on-write
  133. }
  134. hook global WinSetOption filetype=elvish %{
  135. no-tabs 2
  136. }
  137. hook global WinSetOption filetype=nim %{
  138. set buffer gdb_program 'nim-gdb'
  139. no-tabs 2
  140. # 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\"'"
  141. # set buffer lintcmd "sh -c 'nim --stdout --hints:off check $0 | sed \'s/(/:/;s/, /:/;s/)/:/\''"
  142. # lint-on-write
  143. }