-
Notifications
You must be signed in to change notification settings - Fork 0
/
obsidian-vimrc.vim
538 lines (426 loc) · 17.5 KB
/
obsidian-vimrc.vim
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
"───────────────────────────────────────────────────────────────────────────────
" LEADER
" Can't set leaders in Obsidian vim, so the key just has to be used consistently.
" However, it needs to be unmapped, to not trigger default behavior:
" https://github.com/esm7/obsidian-vimrc-support#some-help-with-binding-space-chords-doom-and-spacemacs-fans
unmap ,
"───────────────────────────────────────────────────────────────────────────────
" CLIPBOARD
" yank to system clipboard
set clipboard=unnamed
" Y consistent with D and C to the end of line
nnoremap Y y$
" don't pollute the register (HACK since we can't map to `"_x` or `"_C` directly)
nnoremap C "_c$
nnoremap x "_dl
" nnoremap c "_c " not working with vimrc plugin
" don't override register
vnoremap p P
" paste at EoL
nnoremap P mzA<Space><Esc>p`z
" paste url into selection/cword
" macOS: as opposed to nvim, cmd-key mappings are <M-*>, not <D-*>
noremap <M-k> :pasteinto
"───────────────────────────────────────────────────────────────────────────────
" Copy Path segments
exmap copyAbsolutePath jsfile Meta/vimrc-jsfile.js { copyPathSegment("absolute") }
exmap copyRelativePath jsfile Meta/vimrc-jsfile.js { copyPathSegment("relative") }
exmap copyFilename jsfile Meta/vimrc-jsfile.js { copyPathSegment("filename") }
exmap copyObsidianUriMdLink jsfile Meta/vimrc-jsfile.js { copyObsidianUriMdLink() }
noremap <C-p> :copyAbsolutePath
inoremap <C-p> :copyAbsolutePath
noremap <C-t> :copyRelativePath
inoremap <C-t> :copyRelativePath
noremap <C-n> :copyFilename
inoremap <C-n> :copyFilename
noremap <C-o> :copyObsidianUriMdLink
inoremap <C-o> :copyObsidianUriMdLink
"───────────────────────────────────────────────────────────────────────────────
" NAVIGATION
" navigate visual lines rather than logical ones
nnoremap j gj
nnoremap k gk
nnoremap I g0i
nnoremap A g$a
" HJKL behaves like hjkl, but bigger distance
noremap H g0
noremap L g$
nnoremap J 6gj
nnoremap K 6gk
vnoremap J 6j
vnoremap K 6k
" dj = delete 2 lines, dJ = delete 3 lines
onoremap J 2j
" Jumps
nnoremap <C-h> <C-o>
nnoremap <C-l> <C-i>
" Language tools: next/prev/accept suggestion
exmap nextSuggestion obcommand obsidian-languagetool-plugin:ltjump-to-next-suggestion
noremap ge :nextSuggestion
exmap prevSuggestion obcommand obsidian-languagetool-plugin:ltjump-to-previous-suggestion
noremap gE :prevSuggestion
exmap acceptSuggestion obcommand obsidian-languagetool-plugin:ltaccept-suggestion-1
noremap ga :acceptSuggestion
" next/prev heading
exmap gotoNextHeading jsfile Meta/vimrc-jsfile.js { gotoHeading("next") }
nnoremap <C-j> :gotoNextHeading
exmap gotoPrevHeading jsfile Meta/vimrc-jsfile.js { gotoHeading("prev") }
nnoremap <C-k> :gotoPrevHeading
" [m]atch parenthesis, useful to go to next pandoc citations
nnoremap m %
" [g]oto [s]ymbol (using Another Quick Switcher)
exmap gotoHeading obcommand obsidian-another-quick-switcher:header-floating-search-in-file
nnoremap gs :gotoHeading
" like vim's gx (if not standing on link, seek forward)
exmap openNextLink jsfile Meta/vimrc-jsfile.js { openNextLink("current-tab") }
nnoremap gx :openNextLink
exmap openNextLinkInNewTab jsfile Meta/vimrc-jsfile.js { openNextLink("new-tab") }
nnoremap gX :openNextLinkInNewTab
" [g]oto [f]ootnotes
" requires Footnotes Shortcut Plugin
exmap gotoFootnote obcommand obsidian-footnotes:insert-autonumbered-footnote
nnoremap gf :gotoFootnote
" go to last change (HACK, only works once to jump to the last location)
nnoremap g; u<C-r>
" go to last link in file
exmap gotoLastLinkInFile jsfile Meta/vimrc-jsfile.js { gotoLastLinkInFile() }
nnoremap g. :gotoLastLinkInFile
"───────────────────────────────────────────────────────────────────────────────
" FILE-, TAB- AND WINDOW-NAVIGATION
" [g]oto [o]pen file (= Quick Switcher)
exmap quickSwitcher obcommand obsidian-another-quick-switcher:search-command_main-search
noremap go :quickSwitcher
noremap gr :quickSwitcher
exmap propertySearch obcommand obsidian-another-quick-switcher:search-command_property-search
noremap gp :propertySearch
" :bnext/bprev
exmap goBack obcommand app:go-back
exmap goForward obcommand app:go-forward
noremap <BS> :goBack
noremap <S-BS> :goForward
" Close
exmap closeWindow obcommand workspace:close-window
nnoremap ZZ :closeWindow
" Splits
exmap splitVertical obcommand workspace:split-vertical
noremap <C-w>v :splitVertical
noremap <C-v> :splitVertical
" Tabs
exmap nextTab obcommand workspace:next-tab
exmap prevTab obcommand workspace:previous-tab
nnoremap gt :nextTab
nnoremap gT :prevTab
exmap closeOthers obcommand workspace:close-others
nnoremap <C-w>o :closeOthers
" Alt Buffer (emulates `:buffer #`)
exmap altBuffer obcommand grappling-hook:alternate-note
noremap <CR> :altBuffer
" Random File
exmap openRandomDataFile jsfile Meta/vimrc-jsfile.js { openRandomNoteIn("Data", "read", false) }
noremap <C-Tab> :openRandomDataFile
"───────────────────────────────────────────────────────────────────────────────
" SEARCH
" Find Mode (by mirroring American keyboard layout on German keyboard layout)
nnoremap - /
" <Esc> clears highlights & notices
" (HACK cannot combine excommands, therefore combining them to a mapping first)
exmap clearNotices jsfile Meta/vimrc-jsfile.js { clearNotices() }
nmap &c& :clearNotices
nmap &n& :nohl
nmap <Esc> &c&&n&
" Another Quick Switcher ripgrep-search (somewhat close to Telescope's livegrep)
exmap liveGrep obcommand obsidian-another-quick-switcher:grep
noremap gl :liveGrep
" Obsidian's builtin search & replace
exmap searchReplace obcommand editor:open-search-replace
nnoremap ,ff :searchReplace
nnoremap ,fs :searchReplace
"───────────────────────────────────────────────────────────────────────────────
" EDITING
" Indentation
" <Tab> as indentation is already implemented in Obsidian
" Move lines (doesn't work in visual mode)
exmap lineUp obcommand editor:swap-line-up
exmap lineDown obcommand editor:swap-line-down
nnoremap <Up> :lineUp
nnoremap <Down> :lineDown
" Move character under cursor
nnoremap <Right> dlp
nnoremap <Left> dlhhp
" h1 -> h2, h2 -> h3, etc.
" <M-h> == cmd+h
exmap headingIncrementor jsfile Meta/vimrc-jsfile.js { headingIncrementor() }
nnoremap <M-h> :headingIncrementor
" Move words (equivalent to sibling-swap.nvim)
" nnoremap ä "zdawel"zph
" nnoremap Ä "zdawbh"zph
" above is for single words, below does not trip on ', etc.
nnoremap ä "zdawB"zPB
nnoremap Ä "zdawEl"zpB
" spelling suggestions (emulates `z=`)
exmap contextMenu obcommand editor:context-menu
noremap zl :contextMenu
" undo/redo consistently on one key
nnoremap U <C-r>
" redo all
nnoremap ,ur 1000<C-r>
" toggle lowercase/Titlecase
exmap toggleLowercaseTitleCase jsfile Meta/vimrc-jsfile.js { toggleLowercaseTitleCase() }
nnoremap < :toggleLowercaseTitleCase
" do not move to the right on toggling case
nnoremap ~ v~
" Change word/selection
nnoremap <Space> "_ciw
vnoremap <Space> "_c
onoremap <Space> iw
nnoremap <S-Space> "_daw
" [M]erge lines (removing list or blockquote)
exmap smartMerge jsfile Meta/vimrc-jsfile.js { smartMerge() }
nnoremap M :smartMerge
" [s]plit line
nnoremap ,s i<CR><CR><Esc>
" o and O (respecting list or blockquote)
exmap openBelow jsfile Meta/vimrc-jsfile.js { smartOpenLine("below") }
nnoremap o :openBelow
exmap openAbove jsfile Meta/vimrc-jsfile.js { smartOpenLine("above") }
nnoremap O :openAbove
" Add blank line above/below
nnoremap = mzO<Esc>`z
nnoremap _ mzo<Esc>`z
" Increment/decrement
nnoremap + <C-a>
nnoremap ü <C-x>
" JS Comments
nunmap q
exmap toggleJsLineComment jsfile Meta/vimrc-jsfile.js { toggleJsLineComment() }
nnoremap qq :toggleJsLineComment
exmap appendJsComment jsfile Meta/vimrc-jsfile.js { appendJsComment() }
nnoremap Q :appendJsComment
" markdown tasks
exmap checkList obcommand editor:toggle-checklist-status
nnoremap ,x :checkList
" blockquote
exmap toggleBlockquote obcommand editor:toggle-blockquote
nnoremap ,< :toggleBlockquote
exmap insertHr jscommand { editor.replaceSelection("\n---\n"); }
nnoremap qw :insertHr
"───────────────────────────────────────────────────────────────────────────────
" LEADER MAPPINGS
" [d]evTools
exmap toggleDevtools jscommand { electronWindow.toggleDevTools() }
nnoremap ,d :toggleDevtools
" [L]og Variable
exmap consoleLogFromWordUnderCursor jsfile Meta/vimrc-jsfile.js { consoleLogFromWordUnderCursor() }
nnoremap ,ll :consoleLogFromWordUnderCursor
" Enhance URL with title (same hotkey as [c]ode action in nvim)
exmap enhanceUrlWithTitle obcommand obsidian-auto-link-title:enhance-url-with-title
nnoremap ,cc :enhanceUrlWithTitle
" Freeze Interface
exmap freezeInterface jsfile Meta/vimrc-jsfile.js { freezeInterface() }
nnoremap ,F :freezeInterface
" Rephraser: [a]ccept/[r]eject
exmap acceptSuggestionsInLine jsfile Meta/vimrc-jsfile.js { highlightsAndStrikthrus("accept") }
nnoremap ,a :acceptSuggestionsInLine
exmap rejectSuggestionsInLine jsfile Meta/vimrc-jsfile.js { highlightsAndStrikthrus("reject") }
nnoremap ,r :rejectSuggestionsInLine
" set "[r]ead: true" property
exmap addYamlKey jsfile Meta/vimrc-jsfile.js { addYamlKey("read", true) }
nnoremap ,r :addYamlKey
" [i]nspect [w]ord count
exmap inspectWordCount jsfile Meta/vimrc-jsfile.js { inspectWordCount() }
nnoremap ,iw :inspectWordCount
" [i]nspect chrome [v]ersion
exmap inspectChromeVersion jscommand { new Notice ('Chrome version: ' + process.versions.chrome.split('.')[0], 4000) }
nnoremap ,iv :inspectChromeVersion
"───────────────────────────────────────────────────────────────────────────────
" META: PLUGIN- AND SETTING-RELATED BINDINGS
exmap updatePlugins jsfile Meta/vimrc-jsfile.js { updatePlugins() }
nnoremap ,pp :updatePlugins
" open [p]lugin [d]irectory
exmap openPluginDir jscommand { view.app.openWithDefaultApp(view.app.vault.configDir + '/plugins'); }
nnoremap ,pd :openPluginDir
" open [m]eta
exmap openMetaDir jscommand { view.app.openWithDefaultApp('/Meta'); }
nnoremap ,pm :openMetaDir
" open [s]nippet directory
exmap openSnippetDir jscommand { view.app.openWithDefaultApp(view.app.vault.configDir + '/snippets'); }
nnoremap ,ps :openSnippetDir
" open [t]heme directory
exmap openThemeDir jscommand { view.app.openWithDefaultApp(view.app.vault.configDir + '/themes'); }
nnoremap ,pt :openThemeDir
" open [a]ppearance settings
exmap openAppearanceSettings jsfile Meta/vimrc-jsfile.js { openAppearanceSettings() }
nnoremap ,pa :openAppearanceSettings
" open community plugin settings
exmap openCommunityPluginsSettings jsfile Meta/vimrc-jsfile.js { openCommunityPluginsSettings() }
nnoremap ,pl :openCommunityPluginsSettings
" [i] install [p]lugins
exmap installPlugins jscommand { view.app.workspace.protocolHandlers.get("show-plugin")({ id: ' ' }); }
nnoremap ,pi :installPlugins
" open trash
exmap openTrash jscommand { view.app.openWithDefaultApp("/.trash"); }
nnoremap ,t :openTrash
" dynamic [h]ighlights settings
exmap openDynamicHighlightsSettings jsfile Meta/vimrc-jsfile.js { openDynamicHighlightsSettings() }
nnoremap ,ph :openDynamicHighlightsSettings
" Cycle Colorscheme
exmap cycleColorscheme jsfile Meta/vimrc-jsfile.js { cycleColorscheme() }
nnoremap ,pc :cycleColorscheme
" Open Plugin Settings (uses personal plugin)
exmap openThisVimrc jscommand { view.app.openWithDefaultApp("/Meta/obsidian-vimrc.vim") }
nnoremap g, :openThisVimrc
" Workspace
exmap loadWorkspace jsfile Meta/vimrc-jsfile.js { workspace("load", "Basic") }
nnoremap ,w :loadWorkspace
exmap saveWorkspace jsfile Meta/vimrc-jsfile.js { workspace("save", "Basic") }
nnoremap ,W :saveWorkspace
"───────────────────────────────────────────────────────────────────────────────
" VISUAL MODE
" so repeated "V" selects more lines
vnoremap V gj
" so 2x v goes to visual block mode
vnoremap v <C-v>
"───────────────────────────────────────────────────────────────────────────────
" TEXT OBJECTS
" quicker access to [m]assive word, [q]uote, [z]ingle quote, inline cod[e],
" [r]ectangular bracket, and [c]urly braces
onoremap am aW
onoremap im iW
onoremap aq a"
onoremap iq i"
onoremap az a'
onoremap iz i'
onoremap ae a`
onoremap ie i`
onoremap ir i[
onoremap ar a[
onoremap ac a{
onoremap ic i{
vnoremap am aW
vnoremap im iW
vnoremap aq a"
vnoremap iq i"
vnoremap ay a'
vnoremap iy i'
vnoremap ae a`
vnoremap ie i`
vnoremap ir i[
vnoremap ar a[
vnoremap ac a{
vnoremap ic i{
" emulate some text objects from nvim-various-textobjs
nnoremap ygg ggyG
nnoremap dgg ggdG
nnoremap cgg ggcG
onoremap rg G
vnoremap rg G
onoremap rp }
vnoremap rp }
onoremap m t]
vnoremap m t]
onoremap w t"
vnoremap w t"
onoremap k i"
onoremap K a"
"───────────────────────────────────────────────────────────────────────────────
" SUBSTITUTE
" HACK poor man's substitute.nvim: brut-forcing all possible text objects 💀
nunmap s
nnoremap ss VP
nnoremap S vg$P
nnoremap sj VjP
nnoremap sJ VjjP
nnoremap sim viWP
nnoremap sam vaWP
nnoremap siw viwP
nnoremap saw vawP
nnoremap sis visP
nnoremap sas vasP
nnoremap sip VipP
nnoremap sap VapP
nnoremap sib vi)P
nnoremap saq va"P
nnoremap siq vi"P
nnoremap sk vi"P
nnoremap saz va'P
nnoremap siz vi'P
nnoremap sae va`P
nnoremap sie vi`P
nnoremap sab va)P
nnoremap sir vi]P
nnoremap sar va]P
nnoremap sic vi}P
nnoremap sac va}P
nnoremap srg vGP
nnoremap srp v}P
nnoremap sgg vggGP
nnoremap sm vt]P
"───────────────────────────────────────────────────────────────────────────────
" HACK poor man's duplicate.nvim: brut-forcing all possible text objects 💀
unmap w
nunmap w
nnoremap ww yyp
nnoremap W y$$p
nnoremap wj yjjp
nnoremap wim yiWp
nnoremap wam yaWp
nnoremap wiw yiwp
nnoremap waw yawp
nnoremap wis yisp
nnoremap was yasp
nnoremap wip yipP
nnoremap wap yapP
nnoremap wib yi)p
nnoremap waq ya"p
nnoremap wiq yi"p
nnoremap wk yi"p
nnoremap waz ya'p
nnoremap wiz yi'p
nnoremap wae ya`p
nnoremap wie yi`p
nnoremap wab ya)p
nnoremap wir yi]p
nnoremap war ya]p
nnoremap wic yi}p
nnoremap wac ya}p
nnoremap wrg yGp
nnoremap wrp y}p
nnoremap wm yt]p
"───────────────────────────────────────────────────────────────────────────────
" FOLDING
" Emulate vim folding command
exmap togglefold obcommand editor:toggle-fold
nnoremap za :togglefold
nnoremap ^ :togglefold
nnoremap zo :togglefold
nnoremap zc :togglefold
exmap unfoldall obcommand editor:unfold-all
exmap foldall obcommand editor:fold-all
nnoremap zm :foldall
nnoremap zz :foldall
nnoremap zr :unfoldall
"───────────────────────────────────────────────────────────────────────────────
" OPTION TOGGLING
" [O]ption: [s]pellcheck
exmap spellcheck obcommand editor:toggle-spellcheck
nnoremap ,os :spellcheck
" [O]ption: [n]umbers
exmap toggleLineNumbers jsfile Meta/vimrc-jsfile.js { toggleLineNumbers() }
nnoremap ,on :toggleLineNumbers
" [O]ption: [d]iagnostics
exmap enableDiagnostics obcommand obsidian-languagetool-plugin:ltcheck-text
nnoremap ,od :enableDiagnostics
exmap disableDiagnostics obcommand obsidian-languagetool-plugin:ltclear
nnoremap ,oD :disableDiagnostics
" [O]ption: [a]completion
exmap toggleAiCompletion obcommand copilot-auto-completion:toggle
nnoremap ,oa :toggleAiCompletion
"───────────────────────────────────────────────────────────────────────────────
" AI SUGGESTIONS
" <M-s> = cmd+s
" insert mode: accept suggestion
" normal mode: format
exmap acceptGhostText obcommand copilot-auto-completion:accept
inoremap <M-s> :acceptGhostText
exmap lint obcommand obsidian-linter:lint-file-unless-ignored
nnoremap <M-s> :lint