-
Notifications
You must be signed in to change notification settings - Fork 0
/
obsidianvimrc
183 lines (148 loc) · 5 KB
/
obsidianvimrc
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
" 不支持leader和vimscript"
unmap <Space>
"--------------------- navigate"
" Have j and k navigate visual lines rather than logical ones
nmap j gj
nmap k gk
exmap jumpToLink obcommand mrj-jump-to-link:activate-lightspeed-jump
nmap s :jumpToLink<CR>
" 默认 [[ / ]]"
" exmap next_header obcommand obsidian-editor-shortcuts:goToNextHeading
" nmap ]m :next_header
" exmap prev_header obcommand obsidian-editor-shortcuts:goToPrevHeading
" nmap [m :prev_header
nnoremap + <C-a>
nnoremap - <C-e>
map <C-a> ^
map <C-e> $
" <Esc> clears highlights
nnoremap <Esc> :nohl<CR>
nmap t F
"───────────────────────────────────────────────────────────────────────────────
" CLIPBOARD
" yank to system clipboard
" set clipboard=unnamed
"
" " don't pollute the register (HACK since we can't map to `"_x` or `"_C` directly)
" nnoremap C "_c$
" nnoremap x "_dl
" " BUG not working with vimrc plugin
" nnoremap c "_c
" don't override register
vnoremap p P
" Y consistent with D and C to the end of line
nnoremap Y y$
"───────────────────────────────────────────────────────────────────────────────
" Go back and forward with Ctrl+O and Ctrl+I
" (make sure to remove default Obsidian shortcuts for these to work)
exmap back obcommand app:go-back
exmap forward obcommand app:go-forward
nmap <C-o> :back<CR>
nmap <C-i> :forward<CR>
" alias go to last change
nnoremap g; `.
"--------------------- obsidian action"
"Tab Switching
exmap tabnext obcommand workspace:next-tab
nmap L :tabnext<CR>
exmap tabprev obcommand workspace:previous-tab
nmap H :tabprev<CR>
"global search"
exmap global_search obcommand global-search:open
nmap <Space><Space> :global_search<CR>
vmap <Space><Space> :global_search<CR>
exmap switcher_open obcommand switcher:open
nmap <Space>f :switcher_open<CR>
vmap <Space>f :switcher_open<CR>
exmap cp_open obcommand command-palette:open
nmap <Space>a :cp_open<CR>
vmap <Space>a :cp_open<CR>
exmap raf obcommand file-explorer:reveal-active-file
vmap <Space>e :raf<CR>
nmap <Space>e :raf<CR>
exmap open_link obcommand editor:open-link-in-new-leaf
nmap gd :open_link<CR>
"执行大纲搜索"
exmap show_outline obcommand outline:open
nmap gf :show_outline<CR>
"---------------------- edit"
"unlink (need plugins links)
exmap unlink obcommand links:editor-unlink-link
nmap K :unlink<CR>
"----------------------- surround"
" surround.vim mappings
" 正常模式下默认环绕当前单词"
exmap surround_wiki surround [[ ]]
exmap surround_double_quotes surround " "
exmap surround_single_quotes surround ' '
exmap surround_backticks surround ` `
exmap surround_brackets surround ( )
exmap surround_square_brackets surround [ ]
exmap surround_curly_brackets surround { }
" NOTE: must use 'map' and not 'nmap'
" 只有 surround , 无 delete replace surround
map qi :surround_wiki<CR>
nunmap S
vunmap S
map S" :surround_double_quotes<CR>
map S' :surround_single_quotes<CR>
map S` :surround_backticks<CR>
map S( :surround_brackets<CR>
map S) :surround_brackets<CR>
map S[ :surround_square_brackets<CR>
map S[ :surround_square_brackets<CR>
map S{ :surround_curly_brackets<CR>
map S} :surround_curly_brackets<CR>
"---------------------- edit
exmap insertHr jscommand { editor.replaceSelection("\n---\n"); }
nnoremap ql :insertHr<CR>
" Make o and O respect context(need plugin obsidian-editor-shortcuts, 在代码块和列表按o会自动缩进)
exmap blankBelow obcommand obsidian-editor-shortcuts:insertLineBelow
exmap blankAbove obcommand obsidian-editor-shortcuts:insertLineAbove
nmap &a& :blankAbove<CR>
nmap &b& :blankBelow<CR>
nmap o &b&i
nmap O &a&i
"Folding
exmap togglefold obcommand editor:toggle-fold
nmap zo :togglefold<CR>
nmap zc :togglefold<CR>
nmap za :togglefold<CR>
exmap unfoldall obcommand editor:unfold-all
nmap zR :unfoldall<CR>
exmap foldall obcommand editor:fold-all
nmap zM :foldall<CR>
"───────────────────────────────────────────────────────────────────────────────
" SUBSTITUTE
" HACK poor man's substitute.nvim: brut-forcing all possible text objects 💀
" https://github.com/chrisgrieser/.config/blob/main/obsidian/vimrc/obsidian-vimrc.vim
nunmap gr
nnoremap grr VP
nnoremap gr$ vg$P
nnoremap grj VjP
nnoremap grJ VjjP
nnoremap griW viWP
nnoremap graW vaWP
nnoremap griw viwP
nnoremap graw vawP
nnoremap gris visP
nnoremap gras vasP
nnoremap grip VipP
nnoremap grap VapP
nnoremap grib vi)P
nnoremap grab va)P
nnoremap gra" va"P
nnoremap gri" vi"P
nnoremap gri" vi"P
nnoremap gra' va'P
nnoremap gri' vi'P
nnoremap gra` va`P
nnoremap gri` vi`P
nnoremap gri[ vi]P
nnoremap gra[ va]P
nnoremap gri} vi}P
nnoremap gra} va}P
nnoremap grrg vGP
nnoremap grrp v}P
nnoremap grgg vggGP
nnoremap grm vt]P