-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobsidianvimrc
225 lines (180 loc) · 6.3 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
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
" 不支持leader和vimscript"
unmap <Space>
"--------------------- navigate"
" navigate visual lines rather than logical ones
nmap j gj
nmap k gk
vmap j gj
vmap k gk
nnoremap I g0i
nnoremap A g$a
map <C-a> g^
map <C-e> g$
imap <C-a> <Esc>g^i
imap <C-e> <Esc>g$a
exmap jumpToLink obcommand mrj-jump-to-link:activate-lightspeed-jump
nmap s :jumpToLink<CR>
" obsidian-vimrc-support 现在已经默认支持 [[ / ]]"
" 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>
" <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
" paste url into selection/cword
" INFO on macOS, as opposed to nvim, cmd-key mappings are <M-*>, not <D-*>
" 和ob自带的hotkey行为的区别是:
" ob: N模式下不会自动选中当前词范围创建link,但是光标会默认移动到link的()中
" vim: N模式会自动选中当前次范围创建link, 光标不会自动移动到link的()中
" vim 这个配置并不是利用剪贴板的信息来创建link, 就是常规ob创建links.
" noremap <M-k> :pasteinto<CR>
" ensure compatibility with macOS clipboard managers or other pasting methods
vnoremap <M-v> "+p
" [s]plit line
nnoremap \s i<CR><Esc>
" window controls
" https://github.com/esm7/obsidian-vimrc-support/issues/17#issuecomment-1067189450
" not <C-w>w obcommand
exmap focusRight obcommand editor:focus-right
nmap <C-w>l :focusRight<CR>
exmap focusLeft obcommand editor:focus-left
nmap <C-w>h :focusLeft<CR>
exmap focusTop obcommand editor:focus-top
nmap <C-w>k :focusTop<CR>
exmap focusBottom obcommand editor:focus-bottom
nmap <C-w>j :focusBottom<CR>
exmap splitVertical obcommand workspace:split-vertical
nmap <C-w>v :splitVertical<CR>
exmap splitHorizontal obcommand workspace:split-horizontal
nmap <C-w>s :splitHorizontal<CR>