~piotr-machura/dotfiles

ref: f33288fdbe6c4501197bb837b5c413f8925f3043 dotfiles/.config/kak/kakrc -rw-r--r-- 5.3 KiB
f33288fdPiotr Machura Add separate command section to kakoune config 2 months ago
                                                                                
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
# ---------------------
# KAKOUNE EDITOR CONFIG
# ---------------------

set-option global indentwidth 4
set-option global tabstop 4
set-option global scrolloff 3,3
set-option global ignored_files .git/.*
hook global BufOpenFile .* autoconfigtab
hook global BufNewFile  .* autoconfigtab

# User interface
colorscheme bright
add-highlighter global/ number-lines -hlcursor -separator '╎'
add-highlighter global/ wrap -word -indent -marker '↳ '
add-highlighter global/ show-matching
add-highlighter global/ show-whitespaces -spc ' ' -lf ' ' -tab '⇥' -tabpad ' '
set-option -add global ui_options terminal_assistant=none
set-option -add global ui_options terminal_enable_mouse=false

# KEYMAPS
# -------
alias global wqa write-all-quit

map global normal <c-y> %{: xclip-yank<ret>}
map global normal <c-p> %{: xclip-paste<ret>}

map global normal <space> ,
map global normal , <space>

# Format mode
declare-user-mode format
map global user q %{: enter-user-mode format<ret>} -docstring 'Format mode'
map global format q %{: format<ret>} -docstring 'formatcmd (buffer)'
map global format l %{: lsp-formatting<ret>} -docstring 'lsp (buffer)'
map global format L %{: lsp-range-formatting<ret>} -docstring 'lsp (selection)'
map global format w %{: format-width<ret>} -docstring 'flow (selection)'

# Window mode
declare-user-mode window
map global normal <c-w> %{: enter-user-mode window<ret>} -docstring 'Window mode'
map global window n %{: bn<ret>} -docstring 'next'
map global window p %{: bp<ret>} -docstring 'previous'
map global window d %{: db<ret>} -docstring 'delete'
map global window b %{:b<space>} -docstring 'buffers'
map global window N %{:new<space>} -docstring 'new'
map global window s %{: skim<ret>} -docstring 'skim'

# Comment mode
declare-user-mode comment
map global user c %{: enter-user-mode comment<ret>} -docstring 'Comment mode'
map global comment c %{: comment-line<ret>} -docstring 'line '
map global comment C %{: comment-block<ret>} -docstring 'block'

# Surround mode
declare-user-mode surround
map global user s %{: enter-user-mode surround<ret>} -docstring 'Surround mode'
map global surround a %{: surround<ret>} -docstring 'add'
map global surround c %{: change-surround<ret>} -docstring 'change'
map global surround d %{: delete-surround<ret>} -docstring 'delete'
map global surround t %{: select-surrounding-tag<ret>} -docstring 'select tag'

# View mode
map global view H hhhhh -docstring 'left (5 lines)'
map global view J jjjjj -docstring 'down (5 lines)'
map global view K kkkkk -docstring 'up (5 lines)'
map global view L lllll -docstring 'right (5 lines)'

# Spell mode
declare-user-mode spell
map global user z %{: enter-user-mode spell<ret>} -docstring 'Spell mode'
map global spell a %{: spell-add<ret>} -docstring 'add'
map global spell c %{: spell-clear<ret>} -docstring 'clear'
map global spell n %{: spell-next<ret>} -docstring 'next'
map global spell r %{: spell-replace<ret>} -docstring 'replace'
map global spell e %{: spell en<ret>} -docstring 'check (en)'
map global spell p %{: spell pl<ret>} -docstring 'check (pl)'

# COMMANDS
# --------
define-command skim -docstring 'Choose a file and open it in new client' %{
    terminal \
    sh -ce "f=`sk --height=100`; exec kak -c %val{session} ""$f"""
}

define-command xclip-yank -docstring 'Yank selection into system clipboard' %{
    execute-keys -draft '<a-|> xclip -in -selection clipboard<ret>'
    echo 'yanked selection into system clipboard'
}

define-command xclip-paste -docstring 'Paste from system clipboard' %{
    execute-keys -draft '! xclip -out -selection clipboard<ret>'
    echo 'pasted from system clipboard'
}

declare-option -docstring 'Used by format-width' int fmtwidth 88
define-command format-width \
-docstring 'Format selection with fmt using %opt{fmtwidth}' %{
    execute-keys "| fmt -w %opt{fmtwidth}<ret>"
}

# LSP
# ---
evaluate-commands %sh{
    kak-lsp --kakoune -s "$kak_session" -c "$XDG_CONFIG_HOME/kak/lsp.toml"
}
lsp-enable
set-option global lsp_hover_anchor false
set-option global lsp_diagnostic_line_error_sign ' '
set-option global lsp_diagnostic_line_warning_sign ' '
set-option global lsp_diagnostic_line_info_sign ' '
set-option global lsp_diagnostic_line_hint_sign ' '
map global user l %{: enter-user-mode lsp<ret>} -docstring 'LSP mode'
lsp-inlay-diagnostics-disable global
lsp-inline-diagnostics-disable global

# LANGUAGES
# ---------
hook global WinSetOption filetype=python %{
    add-highlighter shared/python/code/function regex \b([a-zA-Z_]\w*)\h*(?=\() 0:function
}

hook global WinSetOption filetype=sh %{
    set-option buffer formatcmd "shfmt -i %opt{indentwidth} -"
}

hook global WinSetOption filetype=(c|cpp) %sh{
    for ft in c cpp; do
        echo "add-highlighter shared/$ft/code/function regex \b([a-zA-Z_]\w*)\h*(?=\() 0:function"
    done
    echo "set-option buffer formatcmd 'indent -linux'"
    echo "set-option buffer indentwidth 0"
    echo "noexpandtab"
}

hook global WinSetOption filetype=makefile %{
    noexpandtab
}

hook global WinSetOption filetype=xml %{
    set-option buffer indentwidth 2
}

hook global WinSetOption filetype=lua %{
    set-option buffer indentwidth 2
    set-option buffer formatcmd "stylua -"
}

hook global WinSetOption filetype=(html|javascript|css|scss|json|yaml) %{
    set-option buffer indentwidth 2
    set-option buffer formatcmd "prettier --parser %opt{filetype}"
}