aboutsummaryrefslogtreecommitdiff
path: root/autoload/+init.kak
blob: 6f5f607dd992d47ecc6ce4e5167f64158d4c87dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Link builtin autoloads
nop %sh{
  rm -f "$kak_config/autoload/standard-library" || true
  ln -sf "$kak_runtime/rc" "$kak_config/autoload/standard-library" 2>/dev/null || true
  rm -f "$kak_config/autoload/plugins" || true
  ln -sf "$kak_runtime/autoload/plugins" "$kak_config/autoload/plugins" 2>/dev/null || true
}

# Disable indent trimming
set-option global disabled_hooks .*-trim-indent

eval %sh{kak-tree-sitter -dksvv --init "${kak_session}" --with-highlighting --with-text-objects}
eval %sh{kcr init kakoune}

# hook global BufCreate .*[.]tsx %{
#   set-option buffer filetype tsx
#   set-option buffer tree_sitter_lang tsx
#   set-option buffer lsp_language_id typescriptreact
# }

colorscheme phenax
set-option global autoreload yes
set-option global incsearch true
set-option global indentwidth 2
set-option global tabstop 2
set-option -add global path "**"
set-option global startup_info_version 20250603
set-option global scrolloff 10,3
set-option -add global ui_options terminal_enable_mouse=false terminal_set_title=true
# terminal_status_on_top=true

# Modeline
# declare-option -hidden _lsp_modeline_diagnostics "%opt{lsp_diagnostic_error_count}"
# %opt{lsp_modeline_breadcrumbs}
set-option global modelinefmt \
'{StatusLineExtras}%opt{lsp_modeline_progress}
{StatusLineDetails}{{context_info}} {{mode_info}}
%val{cursor_line}/%val{buf_line_count}:%val{cursor_char_column}
{StatusLineBufname}%sh{echo "$kak_bufname" | awk -F/ "{if (NF >= 2) {print \$(NF-1) \"/\" \$NF} else {print \$NF}}"}'

# declare-option line-specs relative_markers
# define-command -hidden update_relative_markers %{
#   evaluate-commands %sh{
#     indicators=14
#     line_specs=$(seq $(($indicators + 1)) | while IFS= read n; do
#       diff=$(echo "($n - ($indicators/2) - 1) * 5" | bc)
#       line=$(echo "$kak_cursor_line + $diff" | bc)
#       if [ "$line" -gt 0 ] && [ ! "$line" = "$kak_cursor_line" ]; then
#         echo -e "$line|{gray}$diff"
#       fi
#     done);
#     echo "set-option window relative_markers %val{timestamp} $(printf ' %s' $line_specs)"
#   }
# }
# hook global WinCreate .* %{
#   hook window NormalIdle .* %{ update_relative_markers }
# }
# add-highlighter global/ flag-lines blue relative_markers

# Highlighters
add-highlighter global/ number-lines -hlcursor -min-digits 3 -separator ' ' -relative
add-highlighter global/ column '%val{cursor_char_column}' ColumnLine
add-highlighter global/ line '%val{cursor_line}' RowLine
add-highlighter global/ regex \h+$ 0:Error # Highlight trailing whitespaces
add-highlighter global/ show-matching -previous
add-highlighter global/ show-whitespaces -spc ' ' -tab '│' -lf '¬' -indent '│'
hook global RegisterModified '/' %{
  # Highlight search
  add-highlighter -override global/search regex "%reg{/}" 0:search
}
add-highlighter global/ regex \b(TODO|FIXME)\b 0:default+rb
add-highlighter global/ regex @(todo|fixme) 0:default+rb

# Misc keys
map global user '<esc>' ': set-register slash ""<ret>' -docstring 'Clear search highlighting'
map global normal '/' '/(?i)' # Remap / to case-insensitive search
map global user '/' '/'
map global user s ': w<ret>' -docstring 'Save'
map global normal <c-j> 15j -docstring '15 down'
map global normal <c-k> 15k -docstring '15 up'

map global user y "<a-|> xclip -selection clipboard<ret>" -docstring "yank the selection into the clipboard"

declare-user-mode system
map global user q ': enter-user-mode system<ret>' -docstring 'System mode'
map global system o ':info %opt{}<left>' -docstring 'Print opt'
map global system v ':info %val{}<left>' -docstring 'Print value'
map global system d ': buffer *debug*<ret>' -docstring 'Switch to debug buffer'
map global system f ':set buffer filetype ' -docstring 'Set filetype'
map global system M ':set buffer makecmd ""<left>' -docstring 'Set compile command'
map global system m ': make<ret>' -docstring 'Compile'
map global system p ': info %sh{ realpath -s --relative-to="$PWD" "$kak_buffile" }<ret>' -docstring 'Print relative file path'
map global system P ': info %val{buffile}<ret>' -docstring 'Print absolute file path'
map global system ! ':info %sh{}<left>' -docstring 'Run command'
map global system t ': terminal %sh{ echo "$SHELL" }<ret>' -docstring 'Open new term'

# Wrapping
set-option global autowrap_column 100
hook global WinSetOption filetype=git-commit %{
  set window autowrap_column 72
  autowrap-enable
}
add-highlighter global/ column '%opt{autowrap_column}' WrapLine
add-highlighter global/ wrap -word -indent # Softwrap long lines
map global normal = '|fmt -w $kak_opt_autowrap_column<ret>' -docstring 'Wrap text with fmt'


# Preserve count for user modes (look for alternatives)
# TODO: Reset count on modechange?
declare-option -hidden int user_mode_count 0
define-command enter-user-mode-with-count -params 1 %{
  set-option window user_mode_count %val{count}
  enter-user-mode %arg{1}
}

# Code mode
declare-user-mode code
map global user c ': enter-user-mode code<ret>' -docstring 'Code mode'
map global code c ': comment-line<ret>' -docstring 'Comment/uncomment lines'
map global code f ': apply-formatting<ret>' -docstring 'Apply configured formatter'
def casecamel %{ exec '`s[-_<space>]<ret>d~<a-i>w' }
def casesnake %{ exec '<a-:><a-;>s-|[a-z][A-Z]<ret>;a<space><esc>s[-\s]+<ret>c_<esc><a-i>w`' }
def casekebab %{ exec '<a-:><a-;>s_|[a-z][A-Z]<ret>;a<space><esc>s[_\s]+<ret>c-<esc><a-i>w`' }
map global code <a-minus> ': casekebab<ret>' -docstring 'kebab-casing'
map global code <a-_> ': casesnake<ret>' -docstring 'snake_casing'
map global code <a-c> ': casecamel<ret>' -docstring 'camelCasing'

declare-user-mode ai
map global code a ': enter-user-mode ai<ret>' -docstring 'AI'
map global ai ! '!ai ""<left>' -docstring 'Insert output'
map global ai | '|ai ""<left>' -docstring 'Replace output'

# Editorconfig
hook global WinCreate ^[^*]+$ %{ editorconfig-load }