-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.mappings-emulation.vim
546 lines (453 loc) · 19.8 KB
/
init.mappings-emulation.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
539
540
541
542
543
544
545
546
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Emulate neovim {{{1
if exists('g:nvim')
" Don't allow neovim to remap `Y` as it's used incredibly often and needs to be pressed
" reliably
silent! nunmap Y
endif
" Clear search highlight, update diff, and redraw screen
nnoremap <C-l> <Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>
" Allow <C-u> and <C-w> to be undone
inoremap <C-u> <C-g>u<C-U>
inoremap <C-w> <C-g>u<C-W>
" Make `*` and `#` work on visual selection. NOTE: overridden by visual-star-search
xnoremap * y/\V<C-r>"<CR>
xnoremap # y?\V<C-r>"<CR>
" Repeat last substitute with all the same flags
nnoremap & :&&<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Emulate Emacs {{{1
" Also to replace the useless and dangerous ^A and ^X in normal mode,
" starting to use ^X as a leader in normal mode, just like in emacs and vim
" insert mode.
" Kill rest of the line
" NOTE: instead of here, we set it in init.plugin-coc.vim because we need trickier logic
if !exists('coc_supported')
inoremap <C-k> <C-o>D
endif
""" File operations
" Disabled because we don't use emacs and these slow down normal-mode <C-x>
" nnoremap <C-x>b :b<Space>
" nnoremap <C-x><C-f> :e<Space>
" nnoremap <C-x><C-s> <Cmd>w<CR>
" inoremap <C-x><C-s> <Cmd>w<CR>
""" Window operations
" Disabled because we don't use emacs and these slow down normal-mode <C-x>
" nnoremap <C-x>2 <C-w>s
" nnoremap <C-x>3 <C-w>v
" nnoremap <C-x>0 <C-w>c
" nnoremap <C-x>1 <C-w>o
" nnoremap <C-x>o <C-w>w
" nnoremap <C-x>+ <C-w>=
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Emulate Apple HIG {{{1
" Based on /Applications/MacVim.app/Contents/Resources/vim/gvimrc
" Disable so we can do it ourselves and avoid <M-Down> overriding vim-visual-multi
" And have VimR behave the same as MacVim
let macvim_skip_cmd_opt_movement = 1
no <D-Left> <Home>
no! <D-Left> <Home>
" Go for word, not WORD
"no <M-Left> <C-Left>
"no! <M-Left> <C-Left>
no <D-Right> <End>
no! <D-Right> <End>
" Go for word, not WORD
"no <M-Right> <C-Right>
"no! <M-Right> <C-Right>
no <D-Up> <C-Home>
ino <D-Up> <C-Home>
"no <M-Up> {
"ino <M-Up> <C-o>{
no <D-Down> <C-End>
ino <D-Down> <C-End>
"no <M-Down> }
"ino <M-Down> <C-o>}
ino <M-BS> <C-w>
ino <D-BS> <C-u>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Emulate common GUI apps {{{1
""" General {{{2
" TODO: could be used as chord prefix cause they're not that useful
call MapSuperKey('q', '<Cmd>confirm qall<CR>')
call MapSuperKey('n', '<Cmd>new<CR>')
call MapSuperKey('e', '<C-F2>', 'all', v:false, v:true)
" NOTE: <C-S-F2> doesn't match the meaning of "Recent Locations" in JetBrains
call MapSuperKey('E', '<C-S-F2>', 'all', v:false, v:true)
call MapSuperKey('F', '<C-F3>', 'all', v:false, v:true)
call MapSuperKey('p', '<C-F4>', 'all', v:false, v:true)
call MapSuperKey('"', '<C-F10>', 'all', v:false, v:true)
call MapControlKey('X', '<Cmd>PlugClean<CR><Cmd>PlugInstall<CR>', ['noremap', 'inoremap'])
call MapControlKey('"', '<Cmd>verbose map<CR>')
""" Splits {{{2
call MapControlKey('R', '<Cmd>vsplit<CR>')
call MapControlKey('S', '<Cmd>split<CR>')
" Make that equivalent to MacVim/VimR's ⌘W
call MapKey('<M-w>', '<Cmd>close<CR>')
" Focus split
call MapControlKey('W', '<C-w>c')
call MapControlKey('O', '<C-w>o')
call MapControlKey('H', '<C-w>h')
call MapControlKey('J', '<C-w>j')
call MapControlKey('K', '<C-w>k')
call MapControlKey('L', '<C-w>l')
" NOTE: <M-z> is different from <C-Tab> because it's for splits and not tabs
call MapKey('<M-z>', '<C-w>p')
" Toggle split orientation
" https://stackoverflow.com/questions/1269603/to-switch-from-vertical-split-to-horizontal-split-fast-in-vim/45994525#45994525
function! ToggleSplitOrientation()
if !exists('t:splitType')
let t:splitType = 'vertical'
endif
if t:splitType == 'vertical'
windo wincmd K
let t:splitType = 'horizontal'
else
windo wincmd H
let t:splitType = 'vertical'
endif
endfunction
call MapControlKey('Bar', '<Cmd>call ToggleSplitOrientation()<CR>', 'all', v:true)
" Equalize splits
call MapSuperOrControlKey('M-)', '<C-w>=')
" Maximize split
if exists('g:gui_running')
let s:key = '<M-S-D-Bar>'
else
let s:key = '<M-C-Bar>'
endif
call MapKey(s:key, '<C-w>_', ['nnoremap'])
call MapKey(s:key, '<C-o><C-w>_<C-o><C-w><Bar>', ['noremap!'])
call MapKey(s:key, '<C-\><C-N><C-w>_<C-\><C-N><C-w><Bar>', ['tnoremap'])
" Change split size
call MapKey('<M-C-S-Up>', '2<C-w>+')
call MapKey('<M-C-S-Down>', '2<C-w>-')
call MapKey('<M-C-S-Left>', '4<C-w><lt>')
call MapKey('<M-C-S-Right>', '4<C-w>>')
" Move splits
call MapKey('<C-M-D-Up>', '<C-w>K')
call MapKey('<C-M-D-Down>', '<C-w>J')
call MapKey('<C-M-D-Left>', '<C-w>H')
call MapKey('<C-M-D-Right>', '<C-w>L')
""" Tabs {{{2
" NOTE: we avoid <C-2> and <C-6> because these are ANSI control characters
" (even Shift isn't pressed
call MapSuperKey('t', '<Cmd>tabnew<CR>')
" NOTE: ⌥⌘W closes a tab because GUI's ⌘W (and our ⇧W) closes a split (like in iTerm)
call MapSuperOrControlKey('M-w', '<Cmd>tabclose<CR>')
" MacVim and VimR steal the ⌥⌘W mapping and don't offer a way to reset it, so we need
" an alternate that BetterTouchTool can route through
if exists('g:gui_running')
call MapKey('<M-S-D-w>', '<Cmd>tabclose<CR>')
endif
" Since MacVim/VimR already define ⌘1, we'll just use map ⌥ for consistency across
" UIs. We can't use ⌃ because ⌃6 is special (and ⌃2 may also act funny). But that's
" ok as we can use BTT to remap.
call MapKey('<M-1>', '<Cmd>tabn 1<CR>')
call MapKey('<M-2>', '<Cmd>tabn 2<CR>')
call MapKey('<M-3>', '<Cmd>tabn 3<CR>')
call MapKey('<M-4>', '<Cmd>tabn 4<CR>')
call MapKey('<M-5>', '<Cmd>tabn 5<CR>')
call MapKey('<M-6>', '<Cmd>tabn 6<CR>')
call MapKey('<M-7>', '<Cmd>tabn 7<CR>')
call MapKey('<M-8>', '<Cmd>tabn 8<CR>')
call MapKey('<M-9>', '<Cmd>tablast<CR>')
call MapKey('<M-{>', '<Cmd>tabprev<CR>')
call MapKey('<M-}>', '<Cmd>tabnext<CR>')
" NOTE: MacVim and VimR already have <C-Tab> mapped
call MapKey('<C-Tab>', 'g<Tab>')
" Mainly for TUI vim
call MapKey('<C-S-Tab>', 'g<Tab>')
call MapControlKey('{', '<Cmd>-tabmove<CR>')
call MapControlKey('}', '<Cmd>+tabmove<CR>')
call MapSuperOrControlKey('M-{', '<Cmd>0tabmove<CR>')
call MapSuperOrControlKey('M-}', '<Cmd>$tabmove<CR>')
""" Movement {{{2
" Wrapped line navigation
call MapKey('<Up>', 'gk')
call MapKey('<Down>', 'gj')
" We have to disable insert-mode because <M-right> is used by Copilot
call MapKey('<M-Left>', 'b', ['nmap', 'vmap'])
call MapKey('<M-Right>', 'w', ['nmap', 'vmap'])
" Move cursor
" NOTE: we don't do this in TUIs because <M-Arrow> is reserved for vim-move
if exists('g:gui_running')
call MapSuperKey('Up', 'gg')
call MapSuperKey('Down', 'G')
call MapSuperKey('Left', '0')
call MapSuperKey('Right', '$')
endif
" Go back/forward and/or CamelCaseMotion
" NOTE: Luckily, iTerm passes <M-D-arrows> through
call MapKey('<M-D-Left>', '<C-O>')
call MapKey('<M-D-Right>', '<C-I>')
call MapKey('<C-Left>', '<Plug>CamelCaseMotion_b')
call MapKey('<C-Right>', '<Plug>CamelCaseMotion_w')
" Go to previous edit location and Delete parts of line
call MapSuperKey('S-BS', 'g;')
call MapSuperOrControlKey('M-S-BS', 'g,')
call MapSuperKey('Del', 'D')
call MapSuperKey('BS', 'd0')
" Go to previous/next git change
call MapKey('<C-S-Up>', '[c', 'all', v:false, v:true)
call MapKey('<C-S-Down>', ']c', 'all', v:false, v:true)
" Go to previous/next method
call MapKey('<C-Up>', '[m')
call MapKey('<C-Down>', ']m')
""" Indent {{{2
" Need to reselect selection
if exists('g:gui_running')
nnoremap <D-]> >>
nnoremap <D-[> <<
noremap! <D-]> <C-t>
noremap! <D-[> <C-d>
vnoremap <D-]> >gv
vnoremap <D-[> <gv
else
" NOTE: can't use `MapKey` because it doesn't handle `<M-[>;` shouldn't
" normalize to `<Esc>[` which is the prefix of escape sequences
nnoremap <M-]> >>
nnoremap <M-[> <<
" We can't use these as they're neded for prev/next copilot suggestion
"noremap! <M-]> <C-t>
"noremap! <M-[> <C-d>
vnoremap <M-]> >gv
vnoremap <M-[> <gv
endif
""" Fold {{{2
" 2022-11-14 MacVim doesn't support modifyOtherKeys yet
" We could fall back to using the meta key but right :alembic:plug
call MapControlKey('-', 'zc')
call MapControlKey('=', 'zo')
call MapControlKey('_', 'zM')
call MapControlKey('+', 'zR')
""" expand-region {{{2
map <S-D-Up> <Plug>(expand_region_expand)
map <S-D-Down> <Plug>(expand_region_shrink)
if exists('g:tui_running')
" iTerm doesn't send the ⌘ modifier
map <S-Up> <Plug>(expand_region_expand)
map <S-Down> <Plug>(expand_region_shrink)
endif
""" visual-multi {{{2
let g:VM_maps = {}
let g:VM_maps["Undo"] = 'u'
let g:VM_maps["Redo"] = '<C-r>'
" Free up <C-g> for visual-multi
" We could use `:f` in the general case but we still need `1<C-q><C-g>` for full path
nnoremap <C-q><C-g> <C-g>
" We prefer to add not replace the existing defaults, so we don't use g:VM_maps
" Because \\gS is hard to remember
nnoremap <C-g> <Plug>(VM-Find-Under)
nnoremap \\S <Plug>(VM-Reselect-Last)
exe 'nnoremap ' . g:NormalizeMetaModifier('<M-?>') . ' <Plug>(VM-Start-Regex-Search)'
exe 'nnoremap ' . g:NormalizeMetaModifier('<M-G>') . ' <Plug>(VM-Select-All)'
exe 'xnoremap ' . g:NormalizeMetaModifier('<M-G>') . ' <Plug>(VM-Visual-All)'
" This is like "Add cursors to line ends"
exe 'xnoremap ' . g:NormalizeMetaModifier('<M-I>') . ' <Plug>(VM-Visual-Cursors)'
" In any case, these don't work
" let g:VM_maps["Find Previous"] = '<C-S-N>'
" let g:VM_maps["Select All Words"] = g:NormalizeMetaModifier('<M-G>')
" even if these do:
" let g:VM_maps["Skip Region"] = g:NormalizeMetaModifier('<M-q>')
" let g:VM_maps["Remove Region"] = g:NormalizeMetaModifier('<M-Q>')
" let g:VM_maps["Visual All"] = g:NormalizeMetaModifier('<M-G>')
function! VM_Start()
nnoremap <buffer> <C-S-G> <Plug>(VM-Find-Prev)
exe 'nnoremap <buffer> ' . g:NormalizeMetaModifier('<M-q>') . ' <Plug>(VM-Skip-Region)'
exe 'nnoremap <buffer> ' . g:NormalizeMetaModifier('<M-Q>') . ' <Plug>(VM-Remove-Region)'
exe 'nnoremap <buffer> ' . g:NormalizeMetaModifier('<M-x>a') . ' <Plug>(VM-Align)'
endfunction
function! VM_Exit()
nunmap <buffer> <C-S-G>
exe 'nunmap <buffer> ' . g:NormalizeMetaModifier('<M-q>')
exe 'nunmap <buffer> ' . g:NormalizeMetaModifier('<M-Q>')
exe 'nunmap <buffer> ' . g:NormalizeMetaModifier('<M-x>a')
endfunction
let g:VM_maps["Add Cursor Up"] = '<M-Up>'
let g:VM_maps["Add Cursor Down"] = '<M-Down>'
"exe 'nnoremap ' . g:NormalizeMetaModifier('<M-Up>') . ' <Plug>(VM-Add-Cursor-Up)'
"exe 'xnoremap ' . g:NormalizeMetaModifier('<M-Up>') . ' <Plug>(VM-Add-Cursor-Up)'
"exe 'nnoremap ' . g:NormalizeMetaModifier('<M-Down>') . ' <Plug>(VM-Add-Cursor-Down)'
"exe 'xnoremap ' . g:NormalizeMetaModifier('<M-Down>') . ' <Plug>(VM-Add-Cursor-Down)'
" NOTE: we can't use <C-Leftmouse> because that's already mapped to looking up tags
" NOTE: we can't use <C-S-RightMouse> because MacVim doesn't pass it through,
" even if we did already liberate <C-LeftMouse> with:
" `defaults write org.vim.MacVim MMTranslateCtrlClick 0` to disable the context menu
" NOTE: iTerm2 sends Cmd+Click as <M-LeftMouse>
let g:VM_maps["Mouse Cursor"] = '<M-RightMouse>'
let g:VM_maps["Mouse Word"] = '<M-MiddleMouse>'
let g:VM_maps["Mouse Column"] = '<S-M-RightMouse>'
""" vim-move {{{2
call MapKey('<C-M-Down>', '<Plug>MoveLineDown', ['nmap', 'map!'])
call MapKey('<C-M-Up>', '<Plug>MoveLineUp', ['nmap', 'map!'])
call MapKey('<C-M-Left>', '<Plug>MoveCharLeft', ['nmap', 'map!'])
call MapKey('<C-M-Right>', '<Plug>MoveCharRight', ['nmap', 'map!'])
call MapKey('<C-M-Up>', '<Plug>MoveBlockUp', ['vmap'])
call MapKey('<C-M-Down>', '<Plug>MoveBlockDown', ['vmap'])
call MapKey('<C-M-Left>', '<Plug>MoveBlockLeft', ['vmap'])
call MapKey('<C-M-Right>', '<Plug>MoveBlockRight', ['vmap'])
" if exists('g:gui_running')
" nmap <M-Down> <Plug>MoveLineDown
" nmap <M-Up> <Plug>MoveLineUp
" nmap <M-Left> <Plug>MoveCharLeft
" nmap <M-Right> <Plug>MoveCharRight
" vmap <M-Down> <Plug>MoveBlockDown
" vmap <M-Up> <Plug>MoveBlockUp
" vmap <M-Left> <Plug>MoveBlockLeft
" vmap <M-Right> <Plug>MoveBlockRight
" else
" nmap <Esc><Down> <Plug>MoveLineDown
" nmap <Esc><Up> <Plug>MoveLineUp
" nmap <Esc><Left> <Plug>MoveCharLeft
" nmap <Esc><Right> <Plug>MoveCharRight
"
" " WARNING: if instead of using h,j,k,l, you tend to use arrow keys for motion
" " in Normal mode, then the mappings below may interfere when you try to exit
" " out of Visual mode with <Esc> and immediately hit an arrow key. In that
" " case, you might want to use the `C` modifier instead as here:
" "vmap <C-Down> <Plug>MoveBlockDown
" "vmap <C-Up> <Plug>MoveBlockUp
" "vmap <C-Left> <Plug>MoveBlockLeft
" "vmap <C-Right> <Plug>MoveBlockRight
" vmap <Esc><Down> <Plug>MoveBlockDown
" vmap <Esc><Up> <Plug>MoveBlockUp
" vmap <Esc><Left> <Plug>MoveBlockLeft
" vmap <Esc><Right> <Plug>MoveBlockRight
" endif
""" Edit text {{{2
" Insert empty line above/below
call MapKey('<C-CR>', 'o')
call MapKey('<S-C-CR>', 'O')
" Delete lines
call MapKey('<C-S-BS>', 'dd')
" Increment/Decrement/Toggle
" Allow remapping so that they work for tpope/vim-speeddating
call MapSuperOrControlKey('M-+', '<C-a>', 'all', v:false, v:true)
call MapSuperOrControlKey('M-_', '<C-x>', 'all', v:false, v:true)
call MapKey('<C-z>', '<Cmd>set opfunc=switch#OpfuncForward<CR>g@l', ['nmap'])
call MapKey('<C-z>', '<Cmd>set opfunc=switch#OpfuncForward<CR>g@lgv', ['vmap'])
call MapKey('<C-z>', '<Cmd>set opfunc=switch#OpfuncForward<CR><C-o>g@l', ['map!'])
""" Edit code {{{2
" Shift argument (using vim-argumentative)
call MapSuperOrControlKey('M-lt', '<,', 'all', v:false, v:true)
call MapSuperOrControlKey('M->', '>,', 'all', v:false, v:true)
" NOTE: as of 2022-11-02, `<Cmd>TComment*` doesn't work with ranges
call MapSuperKey('/', ':TComment<CR>')
call MapSuperOrControlKey('M-/', ':TCommentInline<CR>')
" titlecase
" NOTE: These also work in operator-pending
call MapKey('<M-c>T', 'viW<Plug>Titlecase', ['nmap'])
call MapKey('<M-c>t', '<Plug>Titlecase', ['map'])
call MapKey('<M-c>tt', '<Plug>TitlecaseLine', ['nmap'])
" camelsnek
" NOTE: These don't work in operator-pending mode
call MapKey('<M-c>C', ':CamelB<CR>', ['map'])
call MapKey('<M-c>K', ':Kebab<CR>', ['map'])
" Zcp: PascalCase, a.k.a. MixedCase
call MapKey('<M-c>P', ':Camel<CR>', ['map'])
call MapKey('<M-c>S', ':Snek<CR>', ['map'])
call MapKey('<M-c>_', ':Screm<CR>', ['map'])
" abolish
" NOTE: These don't work in operator-pending mode or visual mode
call MapKey('<M-c>D', 'cr.', ['map'])
""" Code navigation {{{2
call MapKey('<F1>' , 'K', 'all', v:false, v:true)
call MapSuperKey('b', 'gd', 'all', v:false, v:true)
call MapSuperKey('B', 'gy', 'all', v:false, v:true)
call MapSuperOrControlKey('M-b', 'gi', 'all', v:false, v:true)
call MapSuperKey('y', '<Cmd>vsplit<CR>gd', 'all', v:false, v:true)
call MapSuperKey('Y', '<Cmd>vsplit<CR>gy', 'all', v:false, v:true)
call MapSuperKey('i', 'gR', 'all', v:false, v:true)
""" Markdown {{{2
call MapKey('<M-m>p', '<Cmd>MarkdownPreview<CR>')
call MapKey('<M-m><M-p>', '<Cmd>Glow<CR>')
" Tip: for entire lines, don't use `V`; use `val` from textobj-line to avoid spurious newlines
call MapSuperKey('M', 'ysiW`', ['nmap'], v:false, v:true)
call MapSuperKey('M', 'S`', ['vmap'], v:false, v:true)
function! s:MapMarkdown() abort
" NOTE: to get this to work in iTerm, I have to use ⌃ key instead of ⌘, but because
" I personally reserve <C-S-M-letter> to launch apps (with BetterTouchTool),
" I have to rely on BetterTouchTool to map <M-S-D-M> to <M-C-S-M> as intermediary
" 2023-09-12 FIXME: broken everywhere
call MapSuperOrControlKey('M-M', 'O```<Esc>Yjp', ['nmap'], v:false, v:false, '<buffer>')
call MapSuperOrControlKey('M-M', '<Esc>`<lt>O```<Esc>yy`>pgv', ['vmap'], v:false, v:false, '<buffer>')
" XXX: this markdown plugin doesn't work right:
" call MapSuperKey('b', '<Cmd>ruby Markdown::toggle_strong_at_cursor<CR>', ['nmap'], v:false, v:true, '<buffer>')
call MapSuperKey('b', 'mAysiW*.`All', ['nmap'], v:false, v:true, '<buffer>')
call MapSuperKey('b', 'S*gvS*gv<Esc>hh', ["vmap"], v:false, v:true, '<buffer>')
" call MapSuperKey('i', '<Cmd>ruby Markdown::toggle_emphasis_at_cursor<CR>', ['nmap'], v:false, v:true, '<buffer>')
call MapSuperKey('i', 'mAysiW_`Al', ['nmap'], v:false, v:true, '<buffer>')
call MapSuperKey('i', 'S_gv<Esc>h', ["vmap"], v:false, v:true, '<buffer>')
call MapSuperKey('X', 'mAysiW~.`All', ['nmap'], v:false, v:true, '<buffer>')
call MapSuperKey('X', 'S~gvS~gv<Esc>hh', ["vmap"], v:false, v:true, '<buffer>')
call MapSuperKey('D', 'mAysiW=.`All', ['nmap'], v:false, v:true, '<buffer>')
call MapSuperKey('D', 'S=gvS=gv<Esc>hh', ["vmap"], v:false, v:true, '<buffer>')
endfunction
autocmd FileType markdown call <SID>MapMarkdown()
" Shift argument (using vim-argumentative)
"call MapSuperOrControlKey('lt', '', 'all', v:false, v:true)
call MapSuperKey('>', '<Cmd>ToggleCB<CR>')
""" Markdown table mode {{{2
call MapKey('<M-m>t', '<Leader>tm', 'all', v:false, v:true)
call MapKey('<M-m>f', '<Leader>tr', 'all', v:false, v:true)
call MapKey('<M-m>i', '<Leader>tiC', 'all', v:false, v:true)
call MapKey('<M-m>a', '<Leader>tic', 'all', v:false, v:true)
call MapKey('<M-m>x', '<Leader>tdc', 'all', v:false, v:true)
call MapKey('<M-m>d', '<Leader>tdd', 'all', v:false, v:true)
autocmd FileType markdown call MapKey('<M-[>', '[<Bar>', ['map', 'imap'], v:false, v:true, '<buffer>')
autocmd FileType markdown call MapKey('<M-]>', ']<Bar>', ['map', 'imap'], v:false, v:true, '<buffer>')
""" Terminal {{{2
call MapKey('<M-F12>', '<Cmd>call OpenTerminal()<CR>')
if exists('g:nvim')
call MapKey('<M-o>t', ':<C-u>call RevealInTerminal()<CR>')
else
call MapKey('<M-o>t',
\ '<Cmd>let $_term_dir = expand("%:p:h")<CR>' .
\ '<Cmd>call RevealInTerminal()<CR>' .
\ 'cd $_term_dir; unset _term_dir<CR>')
endif
" XXX Don't know why <M-o><M-t> doesn't work, so we have to do `<M-o>T`
call MapKey('<M-o><M-t>', '<Cmd>!iterm2-new-tab-with-path %:p:h<CR>')
call MapKey('<M-o>T', '<Cmd>!iterm2-new-tab-with-path %:p:h<CR>')
""" Internal Apps {{{2
call MapKey('<M-s>i', '<Cmd>verb Sleuth<CR>')
if exists('g:nvim')
call MapControlKey('F', '<Cmd>NvimTreeFindFile<CR>')
else
call MapControlKey('F', '<Cmd>NERDTreeFind<CR>')
endif
" Insert gitmoji
map! <M-x>: <C-x><C-u>
""" External Apps {{{2
if has('mac')
call MapKey('<M-o>/', '<Plug>DashSearch')
call MapKey('<M-o>?', '<Plug>DashGlobalSearch')
endif
call MapKey('<M-o>g', '<Plug>SearchNormal', ['map'])
call MapKey('<M-o>g', '<Plug>SearchVisual', ['vmap'])
" NOTE: for some reason `<Cmd>` doesn't work right in visual mode, so use `:`
" https://github.com/voldikss/vim-browser-search/issues/28
call MapKey('<M-o>w', ':BrowserSearch<CR>')
" FIXME: 2022-11-12 cheat.sh API may have changed
call MapKey('<M-o>p', '<Leader>KB', 'all', v:false, v:true)
call MapKey('<M-o>f', '<Cmd>Reveal<CR>')
call MapKey('<M-o>c', '<Cmd>CodeCurrent<CR>')
""" System clipboard {{{2
" NOTE: MacVim and Vimr, but not Neovide, have the ⌘ versions already mapped
" NOTE: we can't do <C-q><C-c> because <C-c> interrupts
call MapKey('<C-q>c', '"+y', ['vnoremap'])
call MapKey('<C-q>x', '"+d', ['vnoremap'])
call MapKey('<C-q>v', '"+gP')
call MapKey('<D-c>', '"+y', ['vnoremap'])
call MapKey('<D-x>', '"+d', ['vnoremap'])
call MapKey('<D-v>', '"+gP')
""" Settings {{{2
call MapKey('<M-s>w', '<Cmd>set wrap!<CR>')
call MapKey('<M-s>b', '<Cmd>call ToggleBackground()<CR>')
call MapKey('<M-s>c', '<Cmd>call ToggleColorscheme()<CR>')
call MapKey('<M-s>C', '<Cmd>HexokinaseToggle<CR>')
call MapKey('<M-s>/', '<Cmd>call EregexToggle()<CR>')
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Prologue {{{1
" vim:foldmethod=marker: