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

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