-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgvimrc
666 lines (556 loc) · 18.9 KB
/
gvimrc
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
" ============================================================================
" _
" __ ___ _(_)_ __ ___ _ __ ___
" / _` \ \ / / | '_ ` _ \| '__/ __|
" | (_| |\ V /| | | | | | | | | (__
" \__, | \_/ |_|_| |_| |_|_| \___|
" |___/
"
" ----------------------------------------------------------------------------
"
" gvimrc
"
" GUI-specific startup commands for Vim.
"
" http://vimdoc.sourceforge.net/htmldoc/gui.html#gvimrc
"
" Load order:
" vimrc
" after/plugin/*
" gvimrc (This file)
"
" ---------
" About Vim
"
" Vim is a highly configurable text editor for efficiently creating and
" changing any kind of text. It is included as `vi` with most UNIX systems and
" with Apple OS X.
"
" https://www.vim.org/
" ============================================================================
" ============================================================================
" Encoding
" ============================================================================
scriptencoding utf-8
set encoding=utf-8
" ============================================================================
" Visual Bell
" ============================================================================
" Disable visual bell in MacVim.
"
" More information:
" http://unix.stackexchange.com/q/5310
" http://stackoverflow.com/q/16047146
" http://stackoverflow.com/q/18589352
if has("gui_macvim")
set noerrorbells
set vb t_vb=
endif
" ============================================================================
" GUI options
" ============================================================================
" disable right scrollbar
set guioptions-=r
" disable left scrollbar
set guioptions-=L
" Only scroll to the end of the current line.
" set guioptions+=h
" ============================================================================
" Font
" ============================================================================
" SetGuiFont()
"
" Set the GUI font with a font size determined by the screen width.
"
" Fonts must be installed from here:
" https://github.com/abertsch/Menlo-for-Powerline
function! SetGuiFont()
" let screenwidth = system("cscreen | awk '{print $4}' | head -2 | tail -1")
let screenwidth = system("
\ if hash system_profiler 2>/dev/null
\ then
\ system_profiler SPDisplaysDataType | awk '/Resolution/{print $4}'
\ fi")
if screenwidth < "1919\n"
set guifont=MesloLGMDZ\ Nerd\ Font:h11
" Fallbacks
set guifont+=Meslo\ LG\ M\ DZ\ for\ Powerline:h11
set guifont+=Menlo\ for\ Powerline:h11
set guifont+=Menlo:h11
else
set guifont=MesloLGMDZ\ Nerd\ Font:h13
" Fallbacks
set guifont+=Meslo\ LG\ M\ DZ\ for\ Powerline:h13
set guifont+=Menlo\ for\ Powerline:h13
set guifont+=Menlo:h13
endif
endfunction
call SetGuiFont()
" ============================================================================
" Whitespace Display
" ============================================================================
" Whitespace settings are also performed elsewhere in the config process, such
" as in plugins.
"
" Some Janus listchars settings can be found here:
" ~/.vim/core/before/plugin/settings.vim#L26
" Or on github:
" http://git.io/janus-vim-core-before-plugin-settings-vim-L26
" Set end of line character.
"
" Common characters for eol: ¬ $ ~ ¤ ×
" ¬ is used in some other editors, such as Atom.
set listchars+=eol:¬
" Set tab character. Must be a two character string.
"
" Common characters for tabs: ▸ »
" » is used in some other editors, such as Atom.
set listchars+=tab:»\ " trailing space is intended.
" Set space to middle dot.
set listchars+=space:·
" ============================================================================
" Turn off 'u' (undo) and 'q' (recording) key mappings
" ============================================================================
if has("gui_macvim")
nmap q <Nop>
" Turn off the 'u' (undo) key mapping in favor of macOS-standard <D-z>.
nmap u <Nop>
endif
" ============================================================================
" Disable 'cmd-w' (close window) mapping
" ============================================================================
" Disable the 'cmd-w' (close window) and only use :q
" if has("gui_macvim")
" # https://stackoverflow.com/a/8103117
" macm File.Close key=<nop>
" endif
" ============================================================================
" MacVim macmenu
"
" Set Mac-specific properties for {menu}
" ============================================================================
" Remap new tap to command-shift-t (instead of command-t). This works better
" wit CtlrP
if has("gui_macvim")
macmenu &File.New\ Tab key=<D-S-t>
endif
" ============================================================================
" Mouse and Scrolling
" ============================================================================
" sidescrolloff
"
" The minimal number of screen columns to keep to the left and to the
" right of the cursor if 'nowrap' is set.
"
" http://vimdoc.sourceforge.net/htmldoc/options.html#'sidescrolloff'
if !&sidescrolloff
set sidescrolloff=1
endif
" Set `nowrap` and `MMScrollOneDirectionOnly` on MacVim with vim 9.1.0+.
if has("gui_macvim") && v:version >= 901
let scrollOneDirectionOnlyStatus =
\ system("defaults read org.vim.MacVim MMScrollOneDirectionOnly 2>/dev/null")
if scrollOneDirectionOnlyStatus != "1\n"
call system("defaults write org.vim.MacVim MMScrollOneDirectionOnly 1")
endif
set nowrap
endif
" CustomScrollWheelRight()
"
" Only right scroll until all of the longest line is visible in the window.
" When the cursor is not on the longest line and needs to be moved to keep
" scrolling, move it to the longest line, replicating the behavior of
" guioptions-=h
"
" Only works in normal mode.
"
" http://vimdoc.sourceforge.net/htmldoc/options.html#'guioptions'
function! CustomScrollWheelRight()
" Return early if wrap is enabled.
if &wrap
return 0
endif
let l:cursor_column = col(".")
let l:scroll_column = col(".") - wincol() - &fdc + &number * &numberwidth
let l:window_width = winwidth(0) - &fdc - &number * &numberwidth
let l:line_lengths = map(range(1, line('$')), "virtcol([v:val, '$'])")
let l:longest_line_length = max(l:line_lengths)
let l:longest_line_number = index(l:line_lengths , l:longest_line_length) + 1
" Return early if the longest line length is less than the window.
if l:longest_line_length <= l:window_width
return 0
endif
let l:scroll_distance_from_end_of_longest_line =
\ l:longest_line_length - l:window_width - l:scroll_column + 1
let l:current_line_length = strlen(getline("."))
let l:current_line_number = line('$')
let l:distance_to_end_of_current_line =
\ l:current_line_length - l:cursor_column
" Return early if already scrolled to the end of the line.
if l:scroll_distance_from_end_of_longest_line <= 0
return 0
endif
" Move the cursor to the longest line when the end of the current line has
" been reached.
if l:current_line_number != l:longest_line_number
if l:distance_to_end_of_current_line <= 0
call cursor(l:longest_line_number , l:cursor_column)
endif
endif
if l:scroll_distance_from_end_of_longest_line > 6
normal 6zl
else
for i in range(1, l:scroll_distance_from_end_of_longest_line)
normal zl
endfor
endif
endfunction
" ToggleCustomScrollWheelRight()
"
" Initialize CustomScrollWheelRight
"
" NOTE: Additional wrappping settings in after/plugin/dotvim.vim
function! ToggleCustomScrollWheelRight()
if empty(maparg('<ScrollWheelRight>', 'n'))
set nowrap
" NOTE: When set to `nomousefocus`, scrolling in a window without focus
" results in unexpected behavior since the CustomScrollWheelRight()
" calculations are performed in the focused window.
set mousefocus
map <ScrollWheelRight> :call CustomScrollWheelRight()<CR>
else
set wrap
set nomousefocus
unmap <ScrollWheelRight>
endif
endfunction
" call ToggleCustomScrollWheelRight()
" ============================================================================
" Custom MacVim HIG Shift Movement Mappings
" ============================================================================
" Enable custom HIG movement and selection settings when running MacVim
"
" Custom mapping location:
" .gvimrc.after
" Original system mappings:
" https://github.com/b4winckler/macvim/blob/master/src/MacVim/gvimrc
"
if has("gui_macvim")
" Disable MacVim system default mappings
let macvim_skip_cmd_opt_movement = 1
" Enable custom MacVim HIG movement mappings.
let custom_macvim_hig_movement = 1
" If the above custom setting is not enabled, fall back to the MacVim
" defaults.
if !exists("custom_macvim_hig_movement")
" Reenable MacVim system default mappings.
unlet macvim_skip_cmd_opt_movement
" Enable MacVIm HIG shift movement related settings. These are not enabled
" by default, but are enabled as a fallback. More info:
" https://git.io/b4winckler-macvim-gvimrc-L71
let macvim_hig_shift_movement = 1
endif
endif
" MacVim default mappings can be found in the default gvimrc:
"
" https://github.com/b4winckler/macvim/blob/master/src/MacVim/gvimrc
if exists("custom_macvim_hig_movement")
" Notable changes from defaults:
"
" ------------------------------------
" Use Visual mode rather than Select
" ------------------------------------
"
" Visual mode has more predictable behavior than select mode and is
" generally eaiser to work with.
"
" ------------------------------------
" Override MacVim right arrow movement
" ------------------------------------
"
" MacVim right arrow movement seems to deviate from expected default OS X
" cursor movement. These mappings make it behave more closely to other OS X
" applications.
" ##########################################################################
" Command / Option Movement Mappings
" ##########################################################################
" ##################
" Command-Left Arrow
" ##################
no <D-Left> <Home>
no! <D-Left> <Home>
" #################
" Option-Left Arrow
" #################
no <M-Left> <C-Left>
no! <M-Left> <C-Left>
" ##################
" Control-Left Arrow
" ##################
no <C-Left> <C-Left>
no! <C-Left> <C-Left>
" ###################
" Command-Right Arrow
" ###################
no <D-Right> <End>
no! <D-Right> <End>
" ##################
" Option-Right Arrow
" ##################
" These mappings:
" Move to end of current word.
"
" Overrides MacVim default mappings:
" Move to beginning of next word.
no <M-Right> e
no! <M-Right> e
ino <M-Right> <C-O>e<Right>
" ###################
" Control-Right Arrow
" ###################
" These mappings:
" Move to end of current word.
no <C-Right> e
no! <C-Right> e
ino <C-Right> <C-O>e<Right>
" ################
" Command-Up Arrow
" ################
no <D-Up> <C-Home>
ino <D-Up> <C-Home>
" ###############
" Option-Up Arrow
" ###############
no <M-Up> {
ino <M-Up> <C-o>{
" ################
" Control-Up Arrow
" ################
no <C-Up> {
ino <C-Up> <C-o>{
" ##################
" Command-Down Arrow
" ##################
no <D-Down> <C-End>
ino <D-Down> <C-End>
" #################
" Option-Down Arrow
" #################
no <M-Down> }
ino <M-Down> <C-o>}
" ##################
" Control-Down Arrow
" ##################
no <C-Down> }
ino <C-Down> <C-o>}
" ##########################################################################
" Backspace / Delete Mappings
" ##########################################################################
" ##################
" Backspace
" ##################
" DeleteNormalWithoutCopyingToClipboard()
"
" Description:
" Delete in normal mode without copying text to clipboard.
function! DeleteNormalWithoutCopyingToClipboard()
set clipboard=
normal x
set clipboard=unnamed,unnamedplus
endfunction
" DeleteVisualWithoutCopyingToClipboard
"
" Description:
" Delete in visual model without copying to clipboard.
function! DeleteVisualWithoutCopyingToClipboard()
set clipboard=
normal gvx
set clipboard=unnamed,unnamedplus
endfunction
" Original (copies deleted text to clipboard)
" nno <BS> hx
" vno <BS> x
"
" Updated (does not copy deleted text to clipboard)
nno <BS> h:<C-u>call DeleteNormalWithoutCopyingToClipboard()<CR>
vno <BS> :<C-u>call DeleteVisualWithoutCopyingToClipboard()<CR>
" ##################
" Option-Backspace
" ##################
ino <M-BS> <C-w>
" ##################
" Command-Backspace
" ##################
ino <D-BS> <C-u>
" ##########################################################################
" Shift Movement and Selection Mappings
" ##########################################################################
" NOTE: selectmode and keymodel settings from original MacVim settings are
" not used here since they enable select mode and this configuration prefers
" visual mode for everything.
" #########################
" Command-Shift-Left Arrow
" #########################
nn <S-D-Left> v0
vn <S-D-Left> 0
" NOTE: Use `<ESC>` for more natural selection behavior.
" - `<ESC>`:
" Always select the character before the cursor.
" - `<C-O>` (ctrl-O):
" Cursor is at end of line: select character before cursor.
" Cursor is not at end of line: select character after cursor.
ino <S-D-Left> <ESC>v0
" ###################################################
" Option-Shift-Left Arrow / Control-Shift-Right Arrow
" ###################################################
" OnlyWhiteSpaceBeforeCursor()
"
" Returns:
" 1 If there is only whitespace before the current cursor position.
" 0 If there are non-whitespace characters before the current cursor
" position.
function! OnlyWhiteSpaceBeforeCursor()
return ! match(
\ strpart(getline('.'), 0, col('.') - 1),
\ "^[[:space:]][[:space:]]*$"
\ )
endfunction
" ShiftLeftArrowMovement()
"
" Description:
" Move the cursor back.
"
" Returns:
" 'b$' When the cursor is in the first column, select just the newline
" on the preceeding line.
" 'o' When there is only whitespace before the cursor, move the cursor to
" the beginning of the current line.
" 'b' Move the cursor to the beginning of the preceeding word.
function! ShiftLeftArrowMovement()
if col('.') == 1
return 'b$'
elseif OnlyWhiteSpaceBeforeCursor()
return '0'
else
return 'b'
endif
endfunction
" Option-Shift-Left Arrow
" These mappings:
" Enter visual mode and move the cursor left.
nn <expr> <S-M-Left> 'v' . ShiftLeftArrowMovement()
vn <expr> <S-M-Left> ShiftLeftArrowMovement()
" NOTE: Use `<ESC>` for more natural selection behavior.
" - `<ESC>`:
" Always select the character before the cursor.
" - `<C-O>` (ctrl-O):
" Cursor is at end of line: select character before cursor.
" Cursor is not at end of line: select character after cursor.
ino <expr> <S-M-Left> '<ESC>v' . ShiftLeftArrowMovement()
" Control-Shift-Right Arrow
" These mappings:
" Enter visual mode and move the cursor left.
nn <expr> <S-C-Left> 'v' . ShiftLeftArrowMovement()
vn <expr> <S-C-Left> ShiftLeftArrowMovement()
" NOTE: Use `<ESC>` for more natural selection behavior.
" - `<ESC>`:
" Always select the character before the cursor.
" - `<C-O>` (ctrl-O):
" Cursor is at end of line: select character before cursor.
" Cursor is not at end of line: select character after cursor.
ino <expr> <S-C-Left> '<ESC>v' . ShiftLeftArrowMovement()
" ######################
" Command-Shift-Up Arrow
" ######################
nn <S-D-Up> vgg
vn <S-D-Up> gg
ino <S-D-Up> <C-O>vgg
" #####################
" Option-Shift-Up Arrow
" #####################
no <S-M-Up> v{
vm <S-M-Up> {
ino <S-M-Up> <ESC>v{
" ######################
" Control-Shift-Up Arrow
" ######################
no <S-C-Up> v{
vm <S-C-Up> {
ino <S-C-Up> <ESC>v{
" ########################
" Command-Shift-Down Arrow
" ########################
nn <S-D-Down> vG
vn <S-D-Down> G
ino <S-D-Down> <C-O>vG
" #######################
" Option-Shift-Down Arrow
" #######################
no <S-M-Down> v}
vn <S-M-Down> }
ino <S-M-Down> <ESC>v}
" ########################
" Control-Shift-Down Arrow
" ########################
no <S-C-Down> v}
vn <S-C-Down> }
ino <S-C-Down> <ESC>v}
" #########################
" Command-Shift-Right Arrow
" #########################
" These mappings:
" Enter visual mode and select rest of line without newline.
"
" Overrides MacVim Default mappings:
" Enter select mode and select to end of line with newline.
nn <S-D-Right> vg_
vn <S-D-Right> g_
ino <S-D-Right> <C-O>vg_
" ####################################################
" Option-Shift-Right Arrow / Control-Shift-Right Arrow
" ####################################################
" OnlyWhiteSpaceAfterCursor()
"
" Returns:
" 1 If there is only whitespace after the current cursor position.
" 0 If there are non-whitespace characters after the current cursor
" position.
function! OnlyWhiteSpaceAfterCursor()
let l:line = getline('.')
let l:column = col('.')
let l:line_length = strwidth(l:line)
return (! match(
\ strpart(l:line, l:column, l:line_length),
\ "^[[:space:]]*$"
\ )) && l:column <= l:line_length
endfunction
" ShiftRightArrowMovement()
"
" Description:
" Move the cursor forward.
"
" Returns:
" '$' When there is only whitespace after the cursor, move the cursor to
" the end of the line.
" 'e' Move the cursor to the end of the next word.
function! ShiftRightArrowMovement()
if OnlyWhiteSpaceAfterCursor()
return '$'
else
return 'e'
endif
endfunction
" These mappings:
" Enter visual mode and move the cursor right.
"
" Overrides MacVim Default mappings:
" Enter select mode and select to beginning of next word.
" Option-Shift-Right Arrow
nn <expr> <S-M-Right> 'v' . ShiftRightArrowMovement()
vn <expr> <S-M-Right> ShiftRightArrowMovement()
ino <expr> <S-M-Right> '<C-O>v' . ShiftRightArrowMovement()
" Control-Shift-Right Arrow
nn <expr> <S-C-Right> 'v' . ShiftRightArrowMovement()
vn <expr> <S-C-Right> ShiftRightArrowMovement()
ino <expr> <S-C-Right> '<C-O>v' . ShiftRightArrowMovement()
endif " exists("custom_macvim_hig_movement")