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.
 
 
 
 
 

171 lines
6.2 KiB

# Merge and manually source plugins
eval %sh{ cat $(find "$kak_config/autosource" -name '*\.kak') }
# Initialization
decl -hidden regex curword
set global ui_options ncurses_assistant=none
set global scrolloff 7,7
set global autoreload yes
set global kitty_window_type os
set global termcmd 'kitty -1 sh -c'
set global grepcmd 'rg -iHL --column'
set global modelinefmt '%opt{modeline_git_branch} %val{bufname}
%val{cursor_line}:%val{cursor_char_column} {{mode_info}} {{context_info}}
◂%val{client}⊙%val{session}▸'
unalias global e edit
alias global e edit-or-dir
face global LineNumbersWrapped black
addhl global/ number-lines -hlcursor -separator ' '
addhl global/ column 80 default,rgb:303030
addhl global/ regex '\h+$' 0:default,red
addhl global/ regex \b(TODO|FIXME|XXX|NOTE)\b 0:default+rb
addhl global/ show-matching
addhl global/ wrap -word -indent -marker ''
addhl global/ dynregex '%reg{/}' 0:+u
addhl global/ dynregex '%opt{curword}' 0:+b
# Keybinds
map global normal <space> ,
map global normal -docstring 'remove all sels except main' <backspace> <space>
map global normal -docstring 'remove main sel' <a-backspace> <a-space>
map global normal -docstring 'comment line' '#' ': comment-line<ret>'
map global normal -docstring 'comment block' '<a-#>' ': comment-block<ret>'
map global normal -docstring 'delete to end of line' D <a-l>d
map global normal -docstring 'yank to end of line' Y <a-l>y
map global user -docstring "add phantom selection" f ': phantom-sel-add-selection<ret>'
map global user -docstring "clear all phantom selections" <a-f> ': phantom-sel-select-all<ret>: phantom-sel-clear<ret>'
map global user -docstring "next phantom selection" F ': phantom-sel-iterate-next<ret>'
map global user -docstring "previous phantom selection" <a-F> ': phantom-sel-iterate-prev<ret>'
map global normal -docstring 'select view' <a-%> ': select-view<ret>'
map global view -docstring 'select view' s '<esc>: select-view<ret>'
map global user -docstring "add mark" m ': mark-word<ret>'
map global user -docstring "clear marks" M ': mark-clear<ret>'
map global user -docstring "expand selection" e ': expand<ret>'
map global user -docstring "expand repeat" E ': expand-repeat<ret>'
map global normal Y ': yank-ring<ret>'
map global normal <c-p> ': yank-ring<ret><c-p>'
map global normal <c-n> ': yank-ring<ret><c-n>'
map global user -docstring 'buffers…' b ': enter-buffers-mode<ret>'
map global user -docstring 'buffers (lock)…' B ': enter-user-mode -lock buffers<ret>'
declare-user-mode surround
map global user -docstring "surround mode" s ': enter-user-mode surround<ret>'
map global surround -docstring 'surround' s ': surround<ret>'
map global surround -docstring 'change' c ': change-surround<ret>'
map global surround -docstring 'delete' d ': delete-surround<ret>'
map global surround -docstring 'select tag' t ': select-surrounding-tag<ret>'
map global surround -docstring 'auto-pairs surround' a ': auto-pairs-surround<ret>'
declare-user-mode anchor
map global normal ';' ': enter-user-mode anchor<ret>'
map global anchor -docstring 'reduce to anchor' a '<a-;>;'
map global anchor -docstring 'reduce to cursor' c ';'
map global anchor -docstring 'flip cursor and anchor' f '<a-;>'
map global anchor -docstring 'ensure anchor after cursor' h '<a-:><a-;>'
map global anchor -docstring 'ensure cursor after anchor' l '<a-:>'
map global anchor -docstring 'select cursor and anchor' s '<a-S>'
map global user -docstring "clip-paste after" p '<a-!>xsel -b -o<ret>'
map global user -docstring "clip-paste before" P '!xsel -b -o<ret>'
map global user -docstring "clip-paste replace" R '|xsel -b -o<ret>'
map global user -docstring "clip-yank" y '<a-|>xclip -i -f -sel c<ret>'
map global user -docstring "next error" l ': lint-next-error<ret>'
map global user -docstring "previous error" L ': lint-previous-error<ret>'
# Functions
def toggle-highlighter -params .. -docstring 'Toggle highlighter' %{
try %{
addhl window/%arg{@} %arg{@}
echo -markup {green} %arg{@}
} catch %{
rmhl window/%arg{@}
echo -markup {red} %arg{@}
}
}
def lint-on-write -docstring 'Activate linting on buffer write' %{
lint-enable
hook buffer BufWritePost .* %{ lint }
}
def no-tabs -params 0..1 -docstring 'Indent with spaces' %{
eval %sh{ [ -n "$1" ] && printf %s "
set buffer indentwidth $1
set buffer tabstop $1
set buffer softtabstop $1
" }
exec :expandtab<ret>
hook buffer InsertKey <space> %{ try %{
exec -draft h<a-i><space><a-k>^\h+<ret>
exec -with-hooks <tab>
} }
}
def clean-trailing-whitespace -docstring 'Remove trailing whitespace' %{
try %{ exec -draft '%s\h+$<ret>d' }
}
# Hooks
hook global WinDisplay .* info-buffers
hook global WinCreate .* auto-pairs-enable
hook global BufOpenFile .* change-directory-current-buffer
hook global NormalIdle .* %{
try %{ exec -draft '<a-i>w: palette-status<ret>' }
}
hook global BufWritePre .* %{ nop %sh{
mkdir -p "$(dirname "$kak_buffile")"
}}
hook global BufWritePost .* %{ git show-diff }
hook global BufReload .* %{ git show-diff }
hook global NormalIdle .* %{
eval -draft %{ try %{
exec <space><a-i>w <a-k>\A\w+\z<ret>
set buffer curword "\b\Q%val{selection}\E\b"
} catch %{
set buffer curword ''
} }
}
# Filetype detection
hook global BufCreate .*srcpkgs/.+/template$ %{
set buffer filetype sh
def xgensum %{ %sh{ xgensum -i "$kak_buffile" } }
}
hook global BufCreate .*/\.?((sx|xinit)(rc)?|profile) %{ set buffer filetype sh }
hook global BufCreate .*\.ino %{ set buffer filetype cpp }
hook global BufCreate .*\.cs %{ addhl window/java }
hook global BufCreate .*\.rasi %{ set buffer filetype css }
# Filetype settings
hook global WinSetOption filetype=sh %{
set buffer lintcmd 'shellcheck -x -fgcc'
lint-on-write
}
hook global WinSetOption filetype=elvish %{
no-tabs 2
}
hook global WinSetOption filetype=nim %{
set buffer gdb_program 'nim-gdb'
no-tabs 2
# 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\"'"
# set buffer lintcmd "sh -c 'nim --stdout --hints:off check $0 | sed \'s/(/:/;s/, /:/;s/)/:/\''"
# lint-on-write
}