-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
2925 lines (2442 loc) · 80.9 KB
/
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
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
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" ============================================================================
" File: vimrc
" Maintainer: https://github.com/EvanQuan/qvim/
" Version: 3.30.2
"
" Contains optional runtime configuration settings to initialize Vim when it
" starts. For Vim versions before 7.4, this should be linked to the ~/.vimrc
" file as described in the README.md file. Later versions automatically detect
" this as the default user vimrc file. You can learn more about this
" configuraion with:
"
" :help qvim
"
" Press \ or za to toggle category folding/unfolding.
" ============================================================================
" Initial Setup {{{
" The first steps necessary to set up everything.
" Version
" Displayed with lightline-buffer.
"
let g:vimrc_version = '3.30.2'
" Path {{{
" Operating system determines the vim home directory.
" NOTE: As of vimrc 2.0.0, with vim-plug as a manager, operating system
" difference problem can be bypassed with a uniform plugin runtime path.
"
let $MYVIMHOME = '~/.vim'
" $MYVIMRC already exists as a path variable, but defaults to ~/.vimrc
" if it exists. To prevent this, it is redefined to ensure that it links
" to this one.
"
let $MYVIMRC = $MYVIMHOME . '/vimrc'
let $MYPLUGINS = $MYVIMHOME . '/plugged'
let $MYPLUGINCONFIG = $MYVIMHOME . '/plugins.vim'
let $MYGITPLUGINS = $MYVIMHOME . '/bundle'
let $MYDOC = $MYVIMHOME . '/doc'
let $MYQVIMDOC = $MYDOC . '/qvim.txt'
let $MYVERSION = $MYVIMHOME . '/version'
let $MYTEMPLATES = $MYVERSION . '/templates'
let $MYSETTINGS = $MYVIMHOME . '/settings.vim'
let $MYSETTINGSTEMPLATE = $MYTEMPLATES . '/settings.vim'
let $MYNOTES = $MYVIMHOME . '/notes.txt'
let $MYGVIMRC = $MYVIMHOME . '/gvimrc'
let $MYWINDOWSVIMRC = '~/_vimrc'
let $MYWINDOWSVIMRCTEMPLATE = $MYTEMPLATES . '/_vimrc'
let $ANACONDA_PYTHON = '/anaconda3/bin/python'
" Get windows to use .vim over vimfiles
if has('win32') || has('win64')
set runtimepath+=$MYVIMHOME
endif
" }}}
" Settings {{{
" settings.vim determines how some configurations are set
" Copy ~/.vim/template/settings.vim if there is no settings.vim file
" in your ~/.vim/ directory.
"
" In case settings.vim does not exist, settings.vim template is used.
" If that also does not exist, setting variables directly defined here.
" Set settings to 3.3.0 defaults if settings.vim does not exist.
"
if filereadable(expand($MYSETTINGS))
source $MYSETTINGS
elseif filereadable(expand($MYSETTINGSTEMPLATE))
source $MYSETTINGSTEMPLATE
endif
if !exists('g:settings#truecolor')
let g:settings#truecolor = 1
endif
if !exists('g:settings#powerline_symbols')
let g:settings#powerline_symbols = 0
endif
if !exists('g:settings#nerdfont_symbols')
let g:settings#nerdfont_symbols = 0
endif
if !exists('g:settings#colorscheme')
let g:settings#colorscheme = 3
endif
if !exists('g:settings#highlight_cursor_line')
let g:settings#highlight_cursor_line = 1
endif
if !exists('g:settings#highlight_cursor_column')
let g:settings#highlight_cursor_column = 0
endif
if !exists('g:settings#highlight_width_indicator')
let g:settings#highlight_width_indicator = 1
endif
if !exists('g:settings#italics')
let g:settings#italics = 1
endif
if !exists('g:settings#line_numbers')
let g:settings#line_numbers = 2
endif
if !exists('g:settings#wrap')
let g:settings#wrap = 1
endif
if !exists('g:settings#wrap_width')
let g:settings#wrap_width = 78
endif
if !exists('g:settings#whitespace')
let g:settings#whitespace = 2
endif
if !exists('g:settings#escape_alternative')
let g:settings#escape_alternative = 0
endif
if !exists('g:settings#python3_execution')
let g:settings#python3_execution = 1
endif
if !exists('g:settings#cursor_color')
let g:settings#cursor_color = 1
endif
if !exists('g:settings#dev_mode')
let g:settings#dev_mode = 0
endif
" Set statusline to nothing for later commands that increment onto statusline.
" This lets the refresh vimrc command to work without overloading the
" statusline.
"
set statusline=
" }}}
" Feature Support {{{
let has_python = has('python') || has('python3')
" }}}
" Plugins {{{
if filereadable(expand($MYPLUGINCONFIG))
source $MYPLUGINCONFIG
endif
" For plugins to load correctly
" Only do this part when compiled with support for autocommands
"
if has('autocmd')
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
" Revert with ":filetype off"
filetype plugin indent on
" Put these in an autocmd group, so that you can revert them with:
" ":augroup vimStartup | au! | augroup END"
augroup vimStartup
au!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim)
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
endif
" }}}
" }}}
" Appearance {{{
" Color Scheme {{{
if g:settings#italics == 1
let g:onedark_terminal_italics = 1
endif
" When set to "dark", Vim will try to use colors that look good on a dark
" background.
"
" Determine color scheme based on settings.vim
" Lightline color scheme is consistent with main color scheme
"
if g:settings#colorscheme == 3
set background=dark
colorscheme codedark
elseif g:settings#colorscheme == 2
set background=light
colorscheme one
elseif g:settings#colorscheme == 1
set background=dark
colorscheme onedark
endif
" }}}
" Font {{{
" This is not placed in the gvimrc because gvimrc loads after vimrc
" Lightline needs powerline fonts to work correctly. While this can be easily
" set manually for terminals, configuring GUI fonts is a bit more difficult,
" and can be done here.
"
if (has('win32') || has('win64') || has('gui_running')) && !has('gui_macvim')
" NOTE: gVim and terminal on Windows seems to be restricted to a select few
" predefined fonts, even if more fonts are installed. This makes powerline
" fonts on Windows not possible.
" Git Bash for Windows does not consider itself be windows, so
" g:settings#powerline_symbols must be manually disabled in settings.
let g:settings#powerline_symbols = 0
endif
" }}}
" Syntax Highlighting {{{
" Switch syntax highlighting on when the terminal has colors or when using the
" GUI (which always has colors)
"
if &t_Co > 2 || has('gui_running')
" Revert with ":syntax off"
syntax enable
endif
" Use 24-bit (true color) mode in Vim/Neovim when outside tmux. If you're
" using tmux version 2.2 or later, you can remove the outermost $TMUX check
" and use tmux's 24-bit color support (see
" < http://sunaku.github.io/tmux-24bit-color.html#usage > for more
" information.)
"
if g:settings#truecolor
" if (empty($TMUX))
if (has("nvim"))
" For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
" For Neovim > 0.1.5 and Vim > patch 7.4.1799
" < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162
" > Based on Vim patch 7.4.1770 (`guicolors` option)
" < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd
" > < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
if (has("termguicolors"))
set termguicolors
" endif
endif
endif
" }}}
" }}}
" Folding {{{
" Enable folding
"
set foldenable
" Set marker folding by default. Cannot be overridden by ftplugin as vimrc
" loads first.
set foldmethod=marker
set foldlevel=0
" }}}
" Languages {{{
" Default {{{
" Describes how automatic formatting is done.
"
set formatoptions=tcqrn1
" 4-space soft tabs
"
" Number of spaces that a <Tab> in the file counts for.
" Default 8
"
set tabstop=4
" Number of spaces to use for each step of (auto)indent.
"
set shiftwidth=4
" Number of spaces that a <Tab> conunts for while performing editing
" operations.
"
set softtabstop=4
" In Insert mode: use the appropraiate number of spaces to insert a <Tab>.
"
set expandtab " sets tabs to spaces
" Do not round indent to multiple of 'shiftwidth'.
"
set noshiftround
" Insert tabs on the start of a line according to shiftwidth, not tabstop
"
set smarttab
" Copy indent from current line when starting a new line
"
set autoindent
" Copy the previous indentation on autoindenting
"
set copyindent
" }}}
" Auto-Detect {{{
" As a priority, soft or hard tab indentation is determined by what is already
" being used in the current file.
" TODO remove due to sleuth?
" function! TabsOrSpaces() abort
" " Determines whether to use spaces or tabs on the current buffer.
" if getfsize(bufname("%")) > 256000
" " If the file is very large, just use the default, since it will take too
" " long to determine which tab type to use.
" return
" endif
" " To determine priority, get the number of tab indentations and space
" " indentations, and choose the one that is used more frequently
" let numTabs=len(filter(getbufline(bufname("%"), 1, 250), 'v:val =~ "^\\t"'))
" let numSpaces=len(filter(getbufline(bufname("%"), 1, 250), 'v:val =~ "^\\ "'))
" if numTabs > numSpaces
" setlocal noexpandtab " enable hard tabs
" else
" setlocal expandtab
" endif
" endfunction
" " Call the function after opening a buffer
" if has('autocmd')
" autocmd BufReadPost * call TabsOrSpaces()
" endif
" }}}
" }}}
" Mappings {{{
" Easier commands
nnoremap <Return> :
" Leader Key {{{
" This key is used in combination with other keys to perform many customizable
" commands
" default leader is \
"
let mapleader = " "
" }}}
" Editing {{{
" Recursive mapping due to vim-speeddating plugin
" Incrementing and decrementing numbers
"
map + <C-a>
map - <C-x>
" Sequential increment and decrement
map g+ g<C-a>
map g- g<C-x>
" Change {{{
" Replaces the word under cursor with whatever you want
" Similar to ciw
" Repeat with . replaces FOLLOWING occurrences of that word
"
nnoremap c* /\<<C-R>=expand('<cword>')<Return>\>\C<Return>``cgn
" Repeat with . replaces PREVIOUS occurrences of that word
"
nnoremap c# ?\<<C-R>=expand('<cword>')<Return>\>\C<Return>``cgN
" Around/In Line
"
nnoremap cal S
nnoremap cil S
" Around/In Double Quotes
"
nnoremap caq ca"
nnoremap ciq ci"
" Around/In Single Quotes
"
nnoremap caQ ca'
nnoremap ciQ ci'
" Until end of Line
"
nnoremap cL c$
" From start of Line
"
nnoremap cH c^
" }}}
" Delete {{{
" Similar with delete diw
"
nnoremap d* /\<<C-r>=expand('<cword>')<Return>\>\C<Return>``dgn
nnoremap d# ?\<<C-r>=expand('<cword>')<Return>\>\C<Return>``dg
" Around/In Line
"
nnoremap dal dd
" TODO: This pauses for some reason, source not found. Mapped here prevents
" delay. Perhaps source is plugin. Grepping shows no results.
nnoremap dd dd
nnoremap dil S<Esc>
" Around/In Double Quotes
"
nnoremap daq da"
nnoremap diq di"
" Around/In Single Quotes
"
nnoremap daQ da'
nnoremap diQ di'
" }}}
" Spelling {{{
" Suggest spellcheck fixes for current word
"
noremap <Leader>ss z=
" }}}
" Substitute {{{
" Globally in File
"
noremap <Leader>sgf :%s//g<Left><Left>
" First in File
"
noremap <Leader>sff :%s//<Left>
" Globally in Line
"
noremap <Leader>sgl :s//g<Left><Left>
" In Line
"
noremap <Leader>sfl :s//<Left>
" }}}
" Paste {{{
" Put Vim in Paste mode. This is useful if you want to cut or copy some text
" from another window and paste it in Vim. This will avoid unexpected effects.
" Setting this option is useful when using Vim in a terminal, where Vim cannot
" distinguish between typed text and pasted text.
"
function! TogglePasteMode() abort
set paste!
if &paste
echo "-- PASTE ON --"
else
echo "-- PASTE OFF --"
endif
endfunction
noremap <Leader>tp :call TogglePasteMode()<Return>
" Similar to yanking
" Leader prefix added to prevent input lag for normal 'p'
" Current disabled, as special paste commands requires leader prefix.
" nnoremap pp p
" System Clipboard
"
noremap <Leader>pc "+p
" Around/In Word
"
nnoremap <Leader>paw "_dawP
nnoremap <Leader>piw "_diwP
" Around/In Braces
"
nnoremap <Leader>pi{ "_di{P
nnoremap <Leader>pi} "_di}P
nnoremap <Leader>piB "_di{P
nnoremap <Leader>piB "_di}P
" Around/In Brackets
"
nnoremap <Leader>pi[ "_di[P
nnoremap <Leader>pi] "_di]P
" Around/In Double Quotes
"
nnoremap <Leader>pa" "_da"P
nnoremap <Leader>paq "_da"P
nnoremap <Leader>pi" "_di"P
nnoremap <Leader>piq "_di"P
" Around/In Single Quotes
"
nnoremap <Leader>pa' "_da'P
nnoremap <Leader>paQ "_da'P
nnoremap <Leader>pi' "_di'P
nnoremap <Leader>piQ "_di"P
" Parens
"
nnoremap <Leader>pi( "_di(P
nnoremap <Leader>pi) "_di)P
nnoremap <Leader>pib "_di(P
nnoremap <Leader>pib "_di)P
" Greater/less than
nnoremap <Leader>pi< "_di<P
nnoremap <Leader>pi> "_di>P
" Tag
"
nnoremap <Leader>pit "_ditP
" Line
"
nnoremap <Leader>pil "_ddP
" }}}
" Underline {{{
nnoremap <Leader>u- yypVr-j
nnoremap <Leader>u= yypVr=j
" }}}
" Visual {{{
" Around Line
" Selects current line, but in Visual mode, not Visual-Line mode
"
vnoremap al <Esc>0v$
" In Line
" Selects current line, except for end-of-line character, in Visual mode
"
vnoremap il <Esc>0v$h
" Around/In Double Quotes
"
vnoremap aq a"
vnoremap iq i"
" Around/In Single Quotes
"
vnoremap aQ a'
vnoremap iQ i'
" Make Backspace/Delete work as expected in visual modes by deleting the
" selected text
"
vnoremap <BS> x
" Select all (the entire file).
"
vnoremap aa VGo1G
" }}}
" Yank {{{
" System clipboard
"
noremap <Leader>y "+y
" Around/In Line
" Yanks whole line except for end-of-line character
" Similar to yy
"
nnoremap yal Vy
nnoremap yil $v^y
"Around/In Double Quotes
"
nnoremap yaq ya"
nnoremap yiq yi"
"Around/In Single Quotes
"
nnoremap yaQ ya'
nnoremap yiQ yi'
" Until end of Line
"
nnoremap yL y$
" From start of Line
"
nnoremap yH y^
" }}}
" }}}
" Files {{{
" Toggle between the last two files opened in current session.
"
nnoremap <Leader>tf <C-^>
" Edit vimrc
"
nnoremap <silent> <Leader>ev :edit $MYVIMRC<Return>
nnoremap <silent> <Leader>hev :split $MYVIMRC<Return>
nnoremap <silent> <Leader>vev :vsplit $MYVIMRC<Return>
" Edit Windows _vimrc
"
nnoremap <silent> <Leader>ew :edit $MYWINDOWSVIMRC<Return>
nnoremap <silent> <Leader>hew :split $MYWINDOWSVIMRC<Return>
nnoremap <silent> <Leader>vew :vsplit $MYWINDOWSVIMRC<Return>
" Edit Windows _vimrc template
"
nnoremap <silent> <Leader>eW :edit $MYWINDOWSVIMRCTEMPLATE<Return>
nnoremap <silent> <Leader>heW :split $MYWINDOWSVIMRCTEMPLATE<Return>
nnoremap <silent> <Leader>veW :vsplit $MYWINDOWSVIMRCTEMPLATE<Return>
" Edit qvim.txt help documentation
"
nnoremap <silent> <Leader>eq :edit $MYQVIMDOC<Return>
nnoremap <silent> <Leader>heq :split $MYQVIMDOC<Return>
nnoremap <silent> <Leader>veq :vsplit $MYQVIMDOC<Return>
" Edit gvimrc
"
nnoremap <silent> <Leader>eg :edit $MYGVIMRC<Return>
nnoremap <silent> <Leader>heg :split $MYGVIMRC<Return>
nnoremap <silent> <Leader>veg :vsplit $MYGVIMRC<Return>
" Reload vimrc
"
nnoremap <silent> <Leader>Rv :source $MYVIMRC<Return>
" Open settings.vim
"
nnoremap <silent> <Leader>es :edit $MYSETTINGS<Return>
nnoremap <silent> <Leader>hes :split $MYSETTINGS<Return>
nnoremap <silent> <Leader>ves :vsplit $MYSETTINGS<Return>
" Open settings.vim template
"
nnoremap <silent> <Leader>eS :edit $MYSETTINGSTEMPLATE<Return>
nnoremap <silent> <Leader>heS :split $MYSETTINGSTEMPLATE<Return>
nnoremap <silent> <Leader>veS :vsplit $MYSETTINGSTEMPLATE<Return>
" Open notes.txt
"
nnoremap <silent> <Leader>en :edit $MYNOTES<Return>
nnoremap <silent> <Leader>hen :split $MYNOTES<Return>
nnoremap <silent> <Leader>ven :vsplit $MYNOTES<Return>
" .tmux.conf
"
nnoremap <silent> <Leader>et :edit ~/.tmux.conf<Return>
nnoremap <silent> <Leader>het :split ~/.tmux.conf<Return>
nnoremap <silent> <Leader>vet :vsplit ~/.tmux.conf<Return>
" .bashrc
"
nnoremap <silent> <Leader>eb :edit ~/.bashrc<Return>
nnoremap <silent> <Leader>heb :split ~/.bashrc<Return>
nnoremap <silent> <Leader>veb :vsplit ~/.bashrc<Return>
" README.md
"
nnoremap <Leader>eR :edit README.md<Return>
nnoremap <Leader>heR :split README.md<Return>
nnoremap <Leader>veR :vsplit README.md<Return>
" run.sh
"
nnoremap <Leader>er :edit run.sh<Return>
nnoremap <Leader>her :split run.sh<Return>
nnoremap <Leader>ver :vsplit run.sh<Return>
" Makefile
"
nnoremap <Leader>em :edit makefile<Return>
nnoremap <Leader>hem :split makefile<Return>
nnoremap <Leader>vem :vsplit makefile<Return>
" input.txt
"
nnoremap <silent> <Leader>ei :edit input.txt<Return>
nnoremap <silent> <Leader>hei :split input.txt<Return>
nnoremap <silent> <Leader>vei :vsplit input.txt<Return>
" output.txt
"
nnoremap <silent> <Leader>eo :edit output.txt<Return>
nnoremap <silent> <Leader>heo :split output.txt<Return>
nnoremap <silent> <Leader>veo :vsplit output.txt<Return>
" plugins.vim
"
nnoremap <silent> <Leader>ep :edit $MYPLUGINCONFIG<Return>
nnoremap <silent> <Leader>hep :split $MYPLUGINCONFIG<Return>
nnoremap <silent> <Leader>vep :vsplit $MYPLUGINCONFIG<Return>
" }}}
" Folding {{{
" Toggle open/close folds
" Since default leader key is remapped, use it for folding
" Enter doesn't do anything in normal mode. Use it for folding.
"
nnoremap \ za
" Change fold method settings
"
nnoremap <Leader>Ff :set fdm=manual<Return>
nnoremap <Leader>Fi :set fdm=indent<Return>
nnoremap <Leader>Fm :set fdm=marker<Return>
nnoremap <Leader>Fs :set fdm=syntax<Return>
nnoremap <Leader>Fd :set fdm=diff<Return>
" }}}
" Git {{{
nnoremap <Leader>gb :Gblame<Return>
" Open current file, blob, tree, commit, or tag in browser at upstream
" hosting provider.
"
nnoremap <Leader>gx :Gbrowse<Return>
" Diff
"
nnoremap <Leader>gd :Gdiff<Return>
" Status
"
nnoremap <Leader>gs :Gstatus<Return>
" Add/Stage all in current directory
"
nnoremap <Leader>ga :Git add .<Return>
" Write to the current file's path and stage the results.
"
nnoremap <Leader>gw :Gwrite<Return>
" Commit
"
nnoremap <Leader>gc :Gcommit<Return>
" Push
"
nnoremap <Leader>gp :Git push<Return>
" Pull
"
nnoremap <Leader>gl :Git pull<Return>
" Log
nnoremap <Leader>gl :Git log<Return>
" Edit config
"
nnoremap <Leader>ge :Git config -e<Return>
" Edit global config
"
nnoremap <Leader>gg :Git config --global -e<Return>
" }}}
" Formatting {{{
" Repeat last macro.
" NOTE: Overwrites default for enter Ex-mode.
" Use ":" for Ex mode instead (Command mode).
"
noremap Q @@
" Remove all carriage returns (displayed as ^M) from the current file.
" Use when the encodings gets messed up.
"
function! DeleteCarriageReturns() abort
execute "normal mmHmt:%s/\<C-V>\<Return>//ge\<Return>'tzt'm"
echo "-- DELETED CARRIAGE RETURNS --"
endfunction
nnoremap dc :call DeleteCarriageReturns()<Return>
" Delete all trailing whitespace from the current file.
"
function! DeleteTrailingWhitespace() abort
" Store last search
let _s=@/
" Store cursor position
let l = line(".")
let c = col(".")
" Strip white space
%!git stripspace
" Clean up:
" Restore previous search history
let @/=_s
" Restore cursor position
call cursor(1, c)
echo "-- DELETED TRAILING WHITESPACE --"
endfunction
nnoremap dr :call DeleteTrailingWhitespace()<Return>
" }}}
" Layout {{{
" Resize windows
"
nnoremap <C-j> <C-w>+
nnoremap <C-k> <C-w>-
nnoremap <C-l> <C-w>>
nnoremap <C-h> <C-w><
" }}}
" Movement {{{
" Buffers {{{
" Move between buffers
"
" Next buffer
"
nnoremap ]b :bnext<Return>
" Previous buffer
"
nnoremap [b :bprevious<Return>
" Quit current buffer
"
function! QuitCurrentBuffer() abort
execute "bprevious|split|bnext|bdelete"
echo "-- QUIT BUFFER --"
endfunction
nnoremap <Leader>qb :call QuitCurrentBuffer()<Return>
" Quit all buffers except the currently focused one.
" Convenient when hidden buffers accumulate over time.
"
function! QuitHiddenBuffers() abort
let tpbl=[]
call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))')
for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1')
silent execute 'bwipeout' buf
endfor
echo "-- QUIT HIDDEN BUFFERS --"
endfunction
nnoremap <silent> <Leader>qh :call QuitHiddenBuffers()<Return>
" }}}
" Windows {{{
" Split open new window
" NOTE: Functions exist to allow for user input for vim-leader-guide
" but at the cost of no filename autocomplete. This is suboptimal.
" If command is done fast enough without prompting vim-leader-guide, then
" filename completion works.
" Horizontal
"
function! HorizontalSplit() abort
" This function exists for vim-leader-guide compatibility
call feedkeys(":split ")
endfunction
nnoremap <Leader>hs :split<space>
" Vertical
"
function! VerticalSplit() abort
" This function exists for vim-leader-guide compatibility
call feedkeys(":vsplit ")
endfunction
nnoremap <Leader>vs :vsplit<space>
" Directional movement
"
nnoremap <Leader>wh <C-w>h
nnoremap <Leader>wj <C-w>j
nnoremap <Leader>wk <C-w>k
nnoremap <Leader>wl <C-w>l
" Go to next window
"
nnoremap ]w <C-w>w
" Go to previous window
"
nnoremap [w <C-w>W
" Quit window
"
nnoremap <Leader>qw :x<Return>
nnoremap <Leader>wq :x<Return>
" Split
nnoremap <Leader>ws <C-w>s
nnoremap <Leader>wv <C-w>v
" }}}
" Tabs {{{
" Open new tab
nnoremap <Leader>ot :tabe<Return>
" Go to tab :by number
"
nnoremap <Leader>T1 1gt
nnoremap <Leader>T2 2gt
nnoremap <Leader>T3 3gt
nnoremap <Leader>T4 4gt
nnoremap <Leader>T5 5gt
nnoremap <Leader>T6 6gt
nnoremap <Leader>T7 7gt
nnoremap <Leader>T8 8gt
nnoremap <Leader>T9 9gt
nnoremap <Leader>Tf :tabfirst<Return>
nnoremap <Leader>Tl :tablast<Return>
" Go to next tab
" Same as gt
"
nnoremap ]t :tabnext<Return>
" Go to previous tab
" Same as gT
"
nnoremap [t :tabprevious<Return>
" Quit tab
"
nnoremap <Leader>qt tabclose
" }}}
" Session {{{
function! ChangeDirectory() abort
" cd vim into the directory of the current buffer
execute ":cd %:p:h"
echo "Changed current working directory to " . getcwd()
endfunction
nnoremap cd :call ChangeDirectory()<Return>
" }}}
" Within Window {{{
" Move up/down by visual lines instead of by 'literal' lines
" Good for when there is soft wrapping.
" If using count to move up and down, revert back to 'logical' lines so that
" wrapped lines only count as one. Mark the previous location so it can be
" returned to with CTRL-O
"
nnoremap <expr> j (v:count > 1 ? "m'" . v:count . 'j' : 'gj')
nnoremap <expr> k (v:count > 1 ? "m'" . v:count . 'k' : 'gk')
" Non-modifier approach to moving up and down half a window. Since j and
" k already use gj/gk, we might as well make use of these bindings.
"
noremap gj <C-d>
noremap gk <C-u>
" Allow backspacing over autoindent, line breaks, and start of insert action
set backspace=indent,eol,start
set matchpairs+=<:> " use % to jump between pairs
runtime! macros/matchit.vim
" Alternative to Esc key
" Not applied to NORMAL mode due to "j" and "k" being used in movement
" Normally, pressing Esc moves the cursor left by 1.
" Mapping a key to <Esc> does not do this.
" Applying h (move left) moves the cursor left by 2 so hl (left then right),
" makes the behaviour the same as regular Esc
"
if g:settings#escape_alternative == 1
inoremap aa <Esc>hl
vnoremap aa <Esc>hl
elseif g:settings#escape_alternative == 2
inoremap jk <Esc>hl
vnoremap jk <Esc>hl
inoremap kj <Esc>hl
vnoremap kj <Esc>hl
endif
" Search for TODO comments
"
nnoremap ]T /TODO<Return>
nnoremap [T ?TODO<Return>