-
Notifications
You must be signed in to change notification settings - Fork 0
/
.obsidian.vimrc
287 lines (242 loc) · 10.5 KB
/
.obsidian.vimrc
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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" https://github.com/esm7/obsidian-vimrc-support
"
" TIP: to list all Obsidian commands, run `:obcommand` and go to JS console.
" Neovim mappings
" FIXME 2024-02-15: doesn't work
"map <C-l> :nohl
" Have j and k navigate visual lines rather than logical ones
map <Down> gj
map <Up> gk
" FIXME 2024-02-15: don't work
"imap <Down> <C-o>gj
"imap <Up> <C-o>gk
" Interestingly, this works better than in vim at the beginning of the line
imap <C-s> <Esc>hxpka
" 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
map <C-o> :back
exmap forward obcommand app:go-forward
map <C-i> :forward
" Emulate Folding https://vimhelp.org/fold.txt.html#fold-commands
exmap togglefold obcommand editor:toggle-fold
nmap za :togglefold
exmap unfoldall obcommand editor:unfold-all
nmap zR :unfoldall
exmap foldall obcommand editor:fold-all
nmap zM :foldall
" Space must first be unbound
unmap <Space>
nmap <Space><Space> :togglefold
exmap tabnext obcommand workspace:next-tab
nmap gt :tabnext
exmap tabprev obcommand workspace:previous-tab
nmap gT :tabprev
exmap FollowLink obcommand editor:follow-link
nmap gx :FollowLink
" https://forum.obsidian.md/t/vim-o-and-o-dont-respect-current-context/48232/3
" XXX Only works for CM5
"exmap NewlineAndIndent cmcommand newlineAndIndent
"nmap o :NewlineAndIndent
""" vim-surround emulation
" Free up `s` in visual mode
vunmap s
vunmap S
exmap SurroundSquared surround [ ]
" NOTE: ys) doesnt' work
nmap ys] :SurroundSquared
vmap S] :SurroundSquared
map µ] :SurroundSquared
exmap SurroundParens surround ( )
" NOTE: ys) doesnt' work
nmap ys) :SurroundParens
vmap S) :SurroundParens
map µ) :SurroundParens
exmap SurroundAngled surround < >
" NOTE: ys> doesnt' work
nmap ys> :SurroundAngled
vmap S> :SurroundAngled
map µ> :SurroundAngled
exmap SurroundUnderlines surround _ _
" NOTE: ys_ doesnt' work
nmap ys_ :SurroundUnderlines
vmap S_ :SurroundUnderlines
map µ_ :SurroundUnderlines
exmap SurroundDoubleQuotes surround " "
" NOTE: ys" doesnt' work
nmap ys" :SurroundDoubleQuotes
vmap S" :SurroundDoubleQuotes
map µ" :SurroundDoubleQuotes
exmap SurroundSingleQuotes surround ' '
" NOTE: ys' doesnt' work
nmap ys' :SurroundSingleQuotes
vmap S' :SurroundSingleQuotes
map µ' :SurroundSingleQuotes
exmap SurroundBackticks surround ` `
" NOTE: ys` doesnt' work
nmap ys` :SurroundBackticks
vmap S` :SurroundBackticks
map µ` :SurroundBackticks
""" My own surround additions
exmap SurroundStars surround ** **
" NOTE: ys* doesnt' work
nmap ys* :SurroundStars
vmap s* :SurroundStars
map µ* :SurroundStars
exmap SurroundEquals surround == ==
" NOTE: ys= doesnt' work
nmap ys= :SurroundEquals
vmap s= :SurroundEquals
map µ= :SurroundEquals
exmap SurroundWiki surround [[ ]]
" NOTE: ysw doesnt' work
nmap ysw :SurroundWiki
vmap sw :SurroundWiki
map µw :SurroundWiki
""" GUI Emulation mappings
unmap <C-q>
exmap EditVimrc obcommand obsidian-shellcommands:shell-command-d5mbqygiaw
nmap <C-q><C-e> :EditVimrc
" FIXME: can't get any of the imap mappings to work but I can use the Sequence Hotkeys plugin for
" that
" TODO: when https://github.com/replit/codemirror-vim/pull/60 is merged into Obsidian
" we have to get rid of the <A-> and re-test
exmap RenameFile obcommand workspace:edit-file-title
nmap çN :RenameFile
exmap TransformTitlecase obcommand obsidian-editor-shortcuts:transformToTitlecase
nmap çT :TransformTitlecase
" We have to use jscommand to get the selection
" See: https://github.com/esm7/obsidian-vimrc-support/issues/99#issuecomment-1128403004
exmap TransformTitlecaseSelection jscommand { editor.setSelections([selection]); this.app.commands.commands['obsidian-editor-shortcuts:transformToTitlecase'].editorCallback(editor) }
vmap çT :TransformTitlecaseSelection
exmap TableControlBar obcommand table-editor-obsidian:table-control-bar
map µt :TableControlBar
exmap TableFormat obcommand table-editor-obsidian:format-table
map µf :TableFormat
exmap TableInsertColumn obcommand table-editor-obsidian:insert-column
map µi :TableInsertColumn
exmap TableDeleteColumn obcommand table-editor-obsidian:delete-column
map µx :TableDeleteColumn
exmap TableInsertRow obcommand table-editor-obsidian:insert-row
map µO :TableInsertRow
exmap TableDeleteRow obcommand table-editor-obsidian:delete-row
map µd :TableDeleteRow
exmap TableAlignLeft obcommand table-editor-obsidian:left-align-column
map µ<Left> :TableAlignLeft
exmap TableAlignCenter obcommand table-editor-obsidian:center-align-column
map µ<Down> :TableAlignCenter
exmap TableAlignRight obcommand table-editor-obsidian:right-align-column
map µ<Right> :TableAlignRight
exmap ExcelToTable obcommand obsidian-excel-to-markdown-table:excel-to-markdown-table
map µX :ExcelToTable
" NOTE: we also have the plugin Sequence Hotkeys installed which also implements the same chords.
" 2023-09-04 Why is this one `nmap` and the others `map`?
" And why is there no need for `imap`?
exmap CodeBlock obcommand code-block-from-selection:e3dea0f5-37f2-4d79-ae58-490af3228069
nmap µM :CodeBlock
exmap CodeBlockSelection jscommand { editor.setSelections([selection]); this.app.commands.commands['code-block-from-selection:e3dea0f5-37f2-4d79-ae58-490af3228069'].callback() }
vmap µM :CodeBlockSelection
exmap CodeBlockBash obcommand code-block-from-selection:06934685-62e1-4ac2-83c2-b42d2d753d6a
map µB :CodeBlockBash
exmap CodeBlockSelectionBash jscommand { editor.setSelections([selection]); this.app.commands.commands['code-block-from-selection:06934685-62e1-4ac2-83c2-b42d2d753d6a'].callback() }
vmap µB :CodeBlockSelectionBash
exmap CodeBlockJS obcommand code-block-from-selection:4ef365c0-8932-4b1e-9947-844a4128ad71
map µJ :CodeBlockJS
exmap CodeBlockSelectionJS jscommand { editor.setSelections([selection]); this.app.commands.commands['code-block-from-selection:4ef365c0-8932-4b1e-9947-844a4128ad71'].callback() }
vmap µJ :CodeBlockSelectionJS
exmap CodeBlockPython obcommand code-block-from-selection:f8b19c3a-9b67-428d-a88b-892811f5707a
map µP :CodeBlockPython
exmap CodeBlockSelectionPython jscommand { editor.setSelections([selection]); this.app.commands.commands['code-block-from-selection:f8b19c3a-9b67-428d-a88b-892811f5707a'].callback() }
vmap µP :CodeBlockSelectionPython
exmap CodeBlockShell obcommand code-block-from-selection:e4a96b24-7cf7-4c34-95e6-30578c8222ce
map µS :CodeBlockShell
exmap CodeBlockSelectionShell jscommand { editor.setSelections([selection]); this.app.commands.commands['code-block-from-selection:e4a96b24-7cf7-4c34-95e6-30578c8222ce'].callback() }
vmap µS :CodeBlockSelectionShell
exmap CodeBlockPowershell obcommand code-block-from-selection:a5afb22c-5d9f-416e-8a43-9ae4a1497bdd
map µW :CodeBlockPowershell
exmap CodeBlockSelectionPowershell jscommand { editor.setSelections([selection]); this.app.commands.commands['code-block-from-selection:a5afb22c-5d9f-416e-8a43-9ae4a1497bdd'].callback() }
vmap µW :CodeBlockSelectionPowershell
exmap SearchInternet obcommand search-on-internet:search-on-internet
map øw :SearchInternet
exmap OpenDefaultApp obcommand open-with-default-app:open
nmap øo :OpenDefaultApp
exmap RevealInFinder obcommand open-with:show-file-in-explorer
nmap øf :RevealInFinder
exmap RevealInTerminal obcommand obsidian-shellcommands:shell-command-v6sx70npxw
nmap øt :RevealInTerminal
exmap OpenVSCode obcommand open-vscode:open-vscode-via-url
nmap øc :OpenVSCode
exmap OpenMacVim obcommand open-with:open-file-with-macvim
nmap øv :OpenMacVim
exmap OpenVimR obcommand open-with:open-file-with-vimr
nmap øV :OpenVimR
exmap OpenMarkText obcommand open-with:open-file-with-marktext
nmap øm :OpenMarkText
exmap OpenMacDown obcommand open-with:open-file-with-macdown
nmap øM :OpenMacDown
" XXX: These don't work when we have an image open since Vim mode isn't active. Use Sequence Hotkeys.
exmap OpenCleanShot obcommand open-with:open-file-with-cleanshotx
nmap øx :OpenCleanShot
exmap OpenPreview obcommand open-with:open-file-with-preview
nmap øu :OpenPreview
exmap SwitchTheme obcommand theme:switch
nmap ßc :SwitchTheme
exmap SwitchThemeDark obcommand theme:use-dark
nmap ßb :SwitchThemeDark
exmap SwitchThemeLight obcommand theme:use-light
nmap ßB :SwitchThemeLight
exmap ToggleWhitespace obcommand control-characters:toggle
nmap ß<Space> :ToggleWhitespace
exmap ToggleBacklinks obcommand backlink:toggle-backlinks-in-document
map ß/ :ToggleBacklinks
exmap GitOpenView obcommand obsidian-git:open-git-view
map ©© :GitOpenView
exmap GitDiff obcommand obsidian-git:open-diff-view
map ©d :GitDiff
exmap GitBackupAndClose obcommand obsidian-git:backup-and-close
map ©u :GitBackupAndClose
exmap GitCommit obcommand obsidian-git:commit
map ©Ç :GitCommit
exmap GitCommitStaged obcommand obsidian-git:commit-staged
map ©c :GitCommitStaged
exmap GitListChangedFiles obcommand obsidian-git:list-changed-files
map ©t :GitListChangedFiles
exmap GitPull obcommand obsidian-git:pull
map ©j :GitPull
exmap GitPush obcommand obsidian-git:push
map ©k :GitPush
exmap GitStageFile obcommand obsidian-git:stage-current-file
map ©a :GitStageFile
exmap GitUnstageFile obcommand obsidian-git:unstage-current-file
map ©A :GitUnstageFile
exmap GitViewFileOnRemote obcommand obsidian-git:view-file-on-github
map ©o :GitViewFileOnRemote
exmap GitViewHistoryOnRemote obcommand obsidian-git:view-history-on-github
map ©h :GitViewHistoryOnRemote
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Smarter o and O (inserting prefix for markdown lists)
" Source: https://forum.obsidian.md/t/vim-o-and-o-should-respect-current-context/48386/5?u=obsequious
exmap blankBelow obcommand obsidian-editor-shortcuts:insertLineBelow
exmap blankAbove obcommand obsidian-editor-shortcuts:insertLineAbove
nmap o :blankBelow<CR>i
nmap O :blankAbove<CR>i
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" https://github.com/esm7/obsidian-vimrc-support/blob/master/JsSnippets.md
" 2024-10-04 deprecated by https://github.com/esm7/obsidian-vimrc-support/pull/222
"exmap nextHeading jsfile /.obsidian/mdHelpers.js {jumpHeading(true)}
"exmap prevHeading jsfile /.obsidian/mdHelpers.js {jumpHeading(false)}
"nmap ]] :nextHeading
"nmap [[ :prevHeading
" Disabled because of lots of problems: https://github.com/hhhapz/improved-obsidian-vimcursor/issues/1
" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" " https://github.com/hhhapz/improved-obsidian-vimcursor
" "
" " 2022-02-16 Bug with LivePreview
" "nmap 0 :g0
" "nmap $ :gDollar
" nmap [[ :pHead
" nmap ]] :nHead
"
" vmap j gj
" vmap k gk