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

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