-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathkakrc
244 lines (189 loc) · 8.83 KB
/
kakrc
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# User preference
# ───────────────
set-option global makecmd 'make -j8'
set-option global grepcmd 'ag --column'
set-option global ui_options terminal_status_on_top=true
hook global ModuleLoaded clang %{ set-option global clang_options -std=c++20 }
hook global ModuleLoaded tmux %{ alias global terminal tmux-terminal-vertical }
colorscheme gruvbox-dark
add-highlighter global/ show-matching -previous
set-face global CurSearch +u
hook global RegisterModified '/' %{ add-highlighter -override global/search regex "%reg{/}" 0:CurSearch }
hook global WinCreate ^[^*]+$ %{ add-highlighter window/ number-lines -hlcursor }
# Enable editor config
# ────────────────────
hook global BufOpenFile .* %{ editorconfig-load }
hook global BufNewFile .* %{ editorconfig-load }
# Filetype specific hooks
# ───────────────────────
hook global WinSetOption filetype=(c|cpp) %{
clang-enable-autocomplete
clang-enable-diagnostics
alias window lint clang-parse
alias window lint-next-error clang-diagnostics-next
}
hook global WinSetOption filetype=python %{
jedi-enable-autocomplete
lint-enable
set-option global lintcmd 'flake8'
}
map -docstring "xml tag objet" global object t %{c<lt>([\w.]+)\b[^>]*?(?<lt>!/)>,<lt>/([\w.]+)\b[^>]*?(?<lt>!/)><ret>}
# Highlight the word under the cursor
# ───────────────────────────────────
set-face global CurWord +b
hook global NormalIdle .* %{
eval -draft %{ try %{
exec ,<a-i>w <a-k>\A\w+\z<ret>
add-highlighter -override global/curword regex "\b\Q%val{selection}\E\b" 0:CurWord
} catch %{
add-highlighter -override global/curword group
} }
}
# Switch cursor color in insert mode
# ──────────────────────────────────
set-face global InsertCursor default,green+B
hook global ModeChange .*:.*:insert %{
set-face window PrimaryCursor InsertCursor
set-face window PrimaryCursorEol InsertCursor
}
hook global ModeChange .*:insert:.* %{ try %{
unset-face window PrimaryCursor
unset-face window PrimaryCursorEol
} }
# Custom mappings
# ───────────────
map global normal = ':prompt math: %{exec "a%val{text}<lt>esc>|bc<lt>ret>"}<ret>'
# System clipboard handling
# ─────────────────────────
evaluate-commands %sh{
if [ -n "$SSH_TTY" ]; then
copy='printf "\033]52;;%s\033\\" $(base64 | tr -d "\n") > $( [ -n "$kak_client_pid" ] && echo /proc/$kak_client_pid/fd/0 || echo /dev/tty )'
paste='printf "paste unsupported through ssh"'
backend="OSC 52"
else
case $(uname) in
Linux)
if [ -n "$WAYLAND_DISPLAY" ]; then
copy="wl-copy -p"; paste="wl-paste -p"; backend=Wayland
else
copy="xclip -i"; paste="xclip -o"; backend=X11
fi
;;
Darwin) copy="pbcopy"; paste="pbpaste"; backend=OSX ;;
esac
fi
printf "map global user -docstring 'paste (after) from clipboard' p '<a-!>%s<ret>'\n" "$paste"
printf "map global user -docstring 'paste (before) from clipboard' P '!%s<ret>'\n" "$paste"
printf "map global user -docstring 'yank to primary' y '<a-|>%s<ret>:echo -markup %%{{Information}copied selection to %s primary}<ret>'\n" "$copy" "$backend"
printf "map global user -docstring 'yank to clipboard' Y '<a-|>%s<ret>:echo -markup %%{{Information}copied selection to %s clipboard}<ret>'\n" "$copy -selection clipboard" "$backend"
printf "map global user -docstring 'replace from clipboard' R '|%s<ret>'\n" "$paste"
printf "define-command -override echo-to-clipboard -params .. %%{ echo -to-shell-script '%s' -- %%arg{@} }" "$copy"
}
# Various mappings
# ────────────────
map global normal '#' :comment-line<ret>
map global user -docstring 'next lint error' n ':lint-next-error<ret>'
map global normal <c-p> :lint<ret>
map global user -docstring 'gdb helper mode' g ':gdb-helper<ret>'
map global user -docstring 'gdb helper mode (repeat)' G ':gdb-helper-repeat<ret>'
map global user -docstring 'lsp mode' l ':enter-user-mode lsp<ret>'
hook global -always BufOpenFifo '\*grep\*' %{ map global normal <minus> ': grep-next-match<ret>' }
hook global -always BufOpenFifo '\*make\*' %{ map global normal <minus> ': make-next-error<ret>' }
# Enable <tab>/<s-tab> for insert completion selection
# ──────────────────────────────────────────────────────
hook global InsertCompletionShow .* %{ map window insert <tab> <c-n>; map window insert <s-tab> <c-p> }
hook global InsertCompletionHide .* %{ unmap window insert <tab> <c-n>; unmap window insert <s-tab> <c-p> }
# Helper commands
# ───────────────
define-command find -params 1 %{ edit %arg{1} }
complete-command -menu find shell-script-candidates %{ ag -g '' --ignore "$kak_opt_ignored_files" }
define-command mkdir %{ nop %sh{ mkdir -p $(dirname $kak_buffile) } }
define-command ide -params 0..1 %{
try %{ rename-session %arg{1} }
rename-client main
set-option global jumpclient main
new rename-client tools
set-option global toolsclient tools
new rename-client docs
set-option global docsclient docs
}
define-command delete-buffers-matching -params 1 %{
evaluate-commands -buffer * %{
evaluate-commands %sh{ case "$kak_buffile" in $1) echo "delete-buffer" ;; esac }
}
}
declare-option -hidden str swap_buffer_target
define-command swap-buffer-with -override -params 1 -client-completion %{
set-option global swap_buffer_target %val{bufname}
edit -scratch # release current window for other client
evaluate-commands -client %arg{1} "
set-option global swap_buffer_target %%val{bufname}
buffer %opt{swap_buffer_target}
"
delete-buffer # delete the temporary scratch buffer
buffer %opt{swap_buffer_target}
}
declare-option int gdb_server_port 5678
declare-option str gdb_server_cmd "gdbserver :%opt{gdb_server_port}"
define-command gdb-server -params .. %{
fifo %opt{gdb_server_cmd} %arg{@}
gdb-session-new -ex "target extended-remote :%opt{gdb_server_port}"
}
declare-option str to_asm_cmd 'g++ -O3 -x c++'
declare-option str to_asm_prelude '
#include <utility>
'
declare-option -hidden int to_asm_timestamp 0
define-command to-asm -params .. -docstring %{
Compile selected text with using the to_asm_cmd option and display assembly in the *asm* buffer
} %{
evaluate-commands -save-regs 'ab"|' %{
execute-keys -save-regs '' y
set-register a %opt{to_asm_prelude}
set-register b %opt{to_asm_cmd}
evaluate-commands -try-client %opt{docsclient} %{
edit -scratch *asm*
set-option buffer filetype gas
execute-keys \%R"aP% "|%reg{b} %arg{@} -S - -o - 2>&1|c++filt<ret>" gg
try %{ execute-keys -draft \%s^\h*\.cfi_<ret>xd }
}
}
}
define-command to-asm-enable -docstring %{
Automatically run to-asm on the whole buffer after each change
} %{
remove-hooks window to-asm
hook -group to-asm window NormalIdle .* %{ try %{
%sh{ [ $kak_opt_to_asm_timestamp -eq $kak_timestamp ] && echo "fail" || echo "nop" }
set buffer to_asm_timestamp %val{timestamp}
evaluate-commands -draft %{
execute-keys '%'
to-asm
}
} }
}
define-command diff-buffers -override -params 2 %{
evaluate-commands %sh{
file1=$(mktemp)
file2=$(mktemp)
echo "
evaluate-commands -buffer '$1' write -force $file1
evaluate-commands -buffer '$2' write -force $file2
edit! -scratch *diff-buffers*
set buffer filetype diff
set-register | 'diff -u $file1 $file2; rm $file1 $file2'
execute-keys !<ret>gg
"
}}
complete-command diff-buffers buffer
define-command clang-format-cursor %{
exec -draft <percent>| "clang-format --lines=%val{cursor_line}:%val{cursor_line}" <ret>
}
hook global GlobalSetOption 'makecmd=ninja(-build)?\b.*' %{ complete-command make shell-script-candidates %{ $kak_opt_makecmd -t targets | cut -f 1 -d : } }
hook global GlobalSetOption 'makecmd=bazel\b.*' %{ complete-command make shell-script-candidates %{ bazel query //... } }
# Mail
# ────
hook global BufOpenFile .*/mail/.*/(cur|new|tmp)/[^/]+ %{ set-option buffer filetype mail }
# Load local Kakoune config file if it exists
# ───────────────────────────────────────────
evaluate-commands %sh{ [ -f $kak_config/local.kak ] && echo "source $kak_config/local.kak" }