-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_vimrc
1745 lines (1435 loc) · 55 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
" ----- General Options ----- {{{1
" keep redraw delays on until vimrc ends
set lazyredraw
" Set the character encoding used inside Vim.
" This option has to come before autochdir in order to not trigger
" a bug with relative pathnames on Vim startup.
set encoding=utf-8
" Do not automatically change directories.
" silent! is needed because this option is not available unless certain
" features have been enabled.
silent! set noautochdir
augroup cmdt_auto
" Clear all auto-commands.
autocmd!
" Use clipboard register, if available.
autocmd VimEnter * call <SID>set_clipboard()
augroup END
" copy indent when starting a new line
set autoindent
" autosave before major commands
set autowrite
" dark background
set background=dark
" allow backspacing over newlines and past start of insert
set backspace=indent,eol,start
" don't leave backup files
set nobackup
" If the clipboard register is available, use it for all yank, delete,
" change and put operations.
function! s:got_clipboard()
if !has('clipboard')
return 0
endif
let l:save_clip = @*
let @* = 'xx'
let l:retval = @* ==# 'xx'
let @* = l:save_clip
return l:retval
endfunction
function! <SID>set_clipboard()
" echom "Got clipboard = ".s:got_clipboard()
set clipboard-=unnamed
if s:got_clipboard()
set clipboard+=unnamed
endif
endfunction
" Show menu even when there is only one match.
" Show popup with more info.
if has('nvim')
set completeopt=menuone,preview
else
set completeopt=menuone,popup
endif
" A = :write command with a file name sets alternate file name for the current
" window.
" F = :write command with a file name sets name of buffer if the buffer does not
" have a name.
" s = set buffer options when first entering a buffer
" B = A backslash has no special meaning in mappings, abbreviations, etc.
" vim-peekaboo and many other plugins seem to assume this setting.
set cpoptions=AFsB
" Use histogram diff algorithm and indent heuristic.
if has('nvim-0.3.2') || has("patch-8.1.0360")
set diffopt=filler,internal,algorithm:histogram,indent-heuristic
endif
" Set swapfile location.
let s:vimrc_swapdir = expand('~/vim/swapdir')
if !isdirectory(s:vimrc_swapdir)
call mkdir(s:vimrc_swapdir, 'p', 0700)
endif
execute 'set directory^='.s:vimrc_swapdir
" Display as much of the last line as possible.
set display=lastline
" Do not equalize window heights after closing a window.
set noequalalways
" Expand tabs.
set expandtab
" Detect these fileformats.
set fileformats=unix,dos
" g is on by default for search and replace
set gdefault
" Use ag or rg, if available, for grepprg.
if executable('rg')
set grepprg=rg\ --vimgrep
elseif executable('ag')
set grepprg=ag\ --vimgrep
endif
" GUI cursor options
" In visual mode, the cursor needs to be a little different from the
" selection color for visibility.
set guicursor=n-c:block-Cursor-blinkon0
set guicursor+=v:block-vCursor-blinkon0
set guicursor+=o:hor50-Cursor-blinkon0
set guicursor+=i-ci:ver25-Cursor-blinkon0
set guicursor+=r-cr:hor20-Cursor-blinkon0
set guicursor+=sm:block-Cursor-blinkwait175-blinkoff150-blinkon175
" Disable menus.
set guioptions-=m
" Visual mode controls global window system selection.
" set guioptions+=a
" Use console dialogs.
set guioptions+=c
" Disable toolbar.
set guioptions-=T
" Disable scrollbars.
set guioptions-=l
set guioptions-=L
set guioptions-=r
set guioptions-=R
" hide current buffer when switching to a new file
set hidden
" increase amount of command line history kept
set history=50
" ignore case in searches
set ignorecase
" incremental search
set incsearch
" infer case of completed portion in keyword completion
set infercase
" don't insert two spaces after a period with the join command
set nojoinspaces
" last window always has status line
set laststatus=2
" make non-breaking spaces visible
set listchars+=nbsp:%
" magic search patterns
set magic
" Enable modeline
set modeline
" Enable mouse in console Vim.
set mouse=a
" hide the mouse pointer while typing characters
set mousehide
" Support Ctrl-A and Ctrl-X for letters and hex numbers, not octal
set nrformats=alpha,hex
" Allow find to search in dir tree.
set path+=**
" Set paper size
set printoptions=paper:letter
" show line/column of cursor position
set ruler
" keep at least 5 lines above and below the cursor
set scrolloff=5
" round indent to multiple of shiftwidth
set shiftround
" number of spaces for ^T/^D
set shiftwidth=4
" a = shorten file messages.
" t = truncate file message at the start.
" I = no intro message.
" A = no ATTENTION message when existing swap file is found.
" T = truncate long messages.
set shortmess=atIAT
" show command in status line
set showcmd
" When completing a word in insert mode from the tags file, show both the tag
" name and the search pattern as possible matches.
set showfulltag
" show matching bracket
set showmatch
" override ignorecase if search pattern contains upper case characters
set smartcase
" Customize status line
if v:version >= 700
set statusline=%f%#User1#
else
set statusline=%f%1*
endif
set statusline+=\ [%M%R%W]\ [%{&fileformat}]%y\ B%n%a
set statusline+=\ %=L%l/%L\ C%-4(%c%V/%{strlen(getline('.'))}%)\ %3p%%
" match .err (Watcom C++ errors) files last
" match graphics files and executables last
set suffixes+=.err
set suffixes+=.gif
set suffixes+=.jpg
set suffixes+=.png
set suffixes+=.exe
set suffixes+=.dll
" Default tab stop.
set tabstop=8
" mode for fast tty
set ttyfast
" Enable persistent undo
if has('persistent_undo')
let s:vimrc_undodir = expand('~/vim/undodir')
if !isdirectory(s:vimrc_undodir)
call mkdir(s:vimrc_undodir, 'p', 0700)
endif
execute 'set undodir^='.s:vimrc_undodir
set undofile
endif
" allow cursor to wrap across line boundaries for all commands
set whichwrap=b,s,h,l,<,>,[,]
" Show command line completion menu.
set wildmenu
" ----- Initialization ----- {{{1
" clear all mappings
nmapclear
vmapclear
omapclear
imapclear
cmapclear
" ===== Install vim-plug and plugins =====
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
" Changes Vim working directory to project root (identified by presence of known directory or file).
Plug 'airblade/vim-rooter'
" Don't echo project directory.
let g:rooter_silent_chdir = 1
" Switch between single-line and multiline forms of code
Plug 'AndrewRadev/splitjoin.vim'
" Destroy all buffers that are not open in any tabs or windows.
Plug 'artnez/vim-wipeout'
" F12 F4 wipes out non-visible buffers.
nnoremap <F12><F4> :Wipeout<cr>
" Plug 'atweiden/vim-dragvisuals'
" Map ctrl-h/j/k/l in visual mode to drag the block.
" vmap <expr> <C-h> DVB_Drag('left')
" vmap <expr> <C-l> DVB_Drag('right')
" vmap <expr> <C-k> DVB_Drag('up')
" vmap <expr> <C-j> DVB_Drag('down')
" vmap <expr> ,d DVB_Duplicate()
" Filetype plugin for csv files
" Plug 'chrisbra/csv.vim'
" Don't conceal delimiters.
let g:csv_no_conceal = 1
" Customize CSV highlights.
highlight CSVColumnEven guifg=gray guibg=#000066 ctermfg=gray ctermbg=DarkBlue
highlight CSVColumnOdd guifg=gray guibg=black ctermfg=gray ctermbg=black
highlight CSVDelimiter guifg=cyan guibg=black ctermfg=cyan ctermbg=black
highlight CSVColumnHeaderEven guifg=green guibg=#000066 ctermfg=green ctermbg=DarkBlue
highlight CSVColumnHeaderOdd guifg=green guibg=black ctermfg=green ctermbg=black
" *** Replaced by mappings to fzf-vim.
" " Active fork of kien/ctrlp.vim—Fuzzy file, buffer, mru, tag, etc finder.
" Plug 'ctrlpvim/ctrlp.vim'
" " Use CtrlPMRU as default.
" let g:ctrlp_cmd = 'CtrlPMRUFiles'
" " Increase size of MRU cache.
" let g:ctrlp_mruf_max = 2000
" " Don't jump to an existing window when opening a file.
" let g:ctrlp_switch_buffer = ''
" " F12 F12: Invoke CtrlP in buffer mode.
" nnoremap <F12><F12> :CtrlPBuffer<cr>
" Pretty, responsive and smooth defaults for a sane ALE, gets you started in 30 seconds
Plug 'desmap/ale-sensible'
" Check syntax in Vim asynchronously and fix files, with Language Server Protocol (LSP) support
Plug 'dense-analysis/ale'
" Only run lint cops. No style cops.
let g:ale_ruby_rubocop_options = '--lint'
" Turn off balloons.
let g:ale_set_balloons = 0
" Fork of vinegar.vim that works with NERDTree.
Plug 'dhruvasagar/vim-vinegar'
" Vim configuration files for Elixir
" Plug 'elixir-editors/vim-elixir'
" Plug 'gabesoft/vim-ags'
" The following autocmd fixes a weird issue with syntax highlighting in the
" vim-ags search results window.
" autocmd BufNewFile,BufRead *.agsv call s:Turn_syntax_on()
" HOCON mode
Plug 'GEverding/vim-hocon'
" Vim script for text filtering and alignment
Plug 'godlygeek/tabular'
" Plug 'haya14busa/incsearch.vim'
" map / <Plug>(incsearch-forward)
" map ? <Plug>(incsearch-backward)
" map g/ <Plug>(incsearch-stay)
" set hlsearch
" let g:incsearch#auto_nohlsearch = 1
" map n <Plug>(incsearch-nohl-n)
" map N <Plug>(incsearch-nohl-N)
" map * <Plug>(incsearch-nohl-*)
" map # <Plug>(incsearch-nohl-#)
" map g* <Plug>(incsearch-nohl-g*)
" map g# <Plug>(incsearch-nohl-g#)
" nnoremap <Esc><Esc> :<C-u>nohlsearch<CR>
" nnoremap v :<C-u>nohlsearch<cr>v
" nnoremap V :<C-u>nohlsearch<cr>V
" nnoremap <C-v> :<C-u>nohlsearch<cr><C-v>
" let g:incsearch#consistent_n_direction = 1
" augroup incsearch-keymap
" autocmd!
" autocmd VimEnter * call s:incsearch_keymap()
" augroup END
" function! s:incsearch_keymap()
" IncSearchNoreMap <C-f> <Over>(incsearch-scroll-f)
" IncSearchNoreMap <C-b> <Over>(incsearch-scroll-b)
" IncSearchNoreMap <PageDown> <Over>(incsearch-scroll-f)
" IncSearchNoreMap <PageUp> <Over>(incsearch-scroll-b)
" IncSearchNoreMap <Right> <Over>(incsearch-next)
" IncSearchNoreMap <Left> <Over>(incsearch-prev)
" IncSearchNoreMap <Tab> <Over>(buffer-complete)
" endfunction
" Plug 'jnwhiteh/vim-golang'
" Plug 'JarrodCTaylor/vim-shell-executor'
" NERDTree and tabs together in Vim, painlessly
Plug 'jistr/vim-nerdtree-tabs'
" Don't open NERDTree on GUI startup.
let g:nerdtree_tabs_open_on_gui_startup = 0
" F7 will toggle NERDTree.
nmap <silent> <F7> <plug>NERDTreeTabsToggle<CR>
" A command-line fuzzy finder
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
" let g:fzf_launcher = '/Users/pcheah/bin/in_a_new_term.sh %s'
nnoremap <C-p> :FZFMru<cr>
nnoremap <C-q> :Files<cr>
nnoremap <f12><f12> :Buffers<cr>
" Show registers when you hit " or @ in normal mode or Ctrl-R in insert mode.
Plug 'junegunn/vim-peekaboo'
" A Vim alignment plugin
Plug 'junegunn/vim-easy-align'
" F12 a invokes EasyAlign.
nmap <F12>a <Plug>(EasyAlign)
vmap <F12>a <Plug>(EasyAlign)
" To get Vim help for vim-plug itself.
Plug 'junegunn/vim-plug'
" This project adds CoffeeScript support to vim. It covers syntax, indenting, compiling, and more.
" Plug 'kchmck/vim-coffee-script'
" Plug 'kien/rainbow_parentheses.vim'
" " F8 toggles rainbow parentheses.
" nnoremap <F8> :RainbowParenthesesToggle<cr>
" General purpose asynchronous tree explorer
" Plug 'lambdalisue/fern.vim'
" Make the fern.vim as a default file explorer instead of Netrw
" Plug 'lambdalisue/fern-hijack.vim'
" collapse or leave action for fern.vim
" Plug 'hrsh7th/fern-mapping-collapse-or-leave.vim'
" let g:fern#mapping#collapse_or_leave#disable_default_mappings = 1
" A Vim plugin that manages your tag files bolt80.com/gutentags
Plug 'ludovicchabant/vim-gutentags'
set statusline+=%{gutentags#statusline('\ [TAGS]')}
let g:gutentags_cache_dir='~/vim/gutentags'
" let g:gutentags_project_root=['.svn', '.git']
" Use your favorite grep tool (ag, ack, git grep, ripgrep, pt, sift, findstr,
" grep) to start an asynchronous search. All matches will be put in a quickfix
" or location list.
" Plug 'mhinz/vim-grepper'
" let g:grepper = {}
" let g:grepper.dir = 'repo,filecwd'
Plug 'mhinz/vim-mix-format'
let g:mix_format_on_save = 1
" Plug 'mileszs/ack.vim'
" Bbye allows you to do delete buffers (close files) without closing your windows or messing up your layout.
Plug 'moll/vim-bbye'
" Plug 'mortonfox/nerdtree-ags'
" NERDTree plugin to add selected path to clipboard
Plug 'mortonfox/nerdtree-clip'
" NERDTree plugin to open the selected folder in iTerm.
Plug 'mortonfox/nerdtree-iterm'
let g:nerdtree_iterm_iterm_version = 3
" Plug 'mortonfox/nerdtree-reuse-currenttab'
" NERDTree customization that stops it from reusing a window from any tab when opening a file node
Plug 'mortonfox/nerdtree-reuse-none'
" Very small, clean but quick and powerful buffer manager!
Plug 'mortonfox/QuickBuf'
" Shift-F4 brings up QuickBuf.
let g:qb_hotkey = '<S-F4>'
Plug 'mzlogin/vim-markdown-toc'
" The Vim RuboCop plugin runs RuboCop and displays the results in Vim
Plug 'ngmy/vim-rubocop'
" Vastly improved Javascript indentation and syntax support in Vim
" Plug 'pangloss/vim-javascript'
" A tree explorer plugin for vim.
Plug 'preservim/nerdtree'
let g:NERDTreeCascadeSingleChildDir=0
" When hitting <cr> in a NERDTree window, open the file in that window even if
" it is already open in another window in the same tab.
let g:NERDTreeCustomOpenArgs = {'file': {'reuse': '', 'where': 'p'}}
" Ctrl-F7 finds the current file in the NERDTree.
nnoremap <silent> <S-F7> :NERDTreeFind<CR>
" async language server protocol plugin for vim and neovim
Plug 'prabirshrestha/async.vim'
Plug 'prabirshrestha/asyncomplete.vim'
Plug 'prabirshrestha/asyncomplete-lsp.vim'
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
" Disable Ruby language server.
let g:lsp_settings = {
\ 'typeprof': {
\ 'disabled': 1,
\ },
\ 'solargraph': {
\ 'disabled': 1,
\ }
\}
" Echo diagnostic error for the current line to status.
let g:lsp_diagnostics_echo_cursor = 1
" Don't automatically show autocomplete popup menu.
let g:asyncomplete_auto_popup = 0
" Don't override user completeopt.
let g:asyncomplete_auto_completeopt = 0
function! s:on_lsp_buffer_enabled() abort
setlocal omnifunc=lsp#complete
setlocal signcolumn=yes
" nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> <f2> <plug>(lsp-rename)
imap <buffer> <c-space> <Plug>(asyncomplete_force_refresh)
endfunction
augroup lsp_install
autocmd!
" call s:on_lsp_buffer_enabled only for languages that have the server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
" Plug 'qpkorr/vim-bufkill'
" Vim and Neovim plugin to reveal the commit messages under the cursor
Plug 'rhysd/git-messenger.vim'
" Plug 'rking/ag.vim'
" Vim configuration for Rust.
" Plug 'rust-lang/rust.vim'
" A solid language pack for Vim.
Plug 'sheerun/vim-polyglot'
" Turn off sensible because otherwise init.vim in vim-polyglot will set tabstop to 2.
let g:polyglot_disabled = ['sensible']
" Vim undo tree visualizer simnalamburt.github.io/vim-mundo
Plug 'simnalamburt/vim-mundo'
nnoremap <F9> :silent MundoToggle<CR>
let g:mundo_right = 1
" Plug 'sjl/gundo.vim'
" nnoremap <F9> :silent GundoToggle<CR>
" let g:gundo_right = 1
" Syntax highlighting for thrift definition files.
" Plug 'solarnz/thrift.vim'
" Easy text exchange operator for Vim
Plug 'tommcdo/vim-exchange'
" A simple alignment operator for Vim text editor
Plug 'tommcdo/vim-lion'
" commentary.vim: comment stuff ou
Plug 'tpope/vim-commentary'
let g:commentary_map_backslash=0
" Plug 'tpope/vim-dispatch'
" fugitive.vim: A Git wrapper so awesome, it should be illegal
Plug 'tpope/vim-fugitive'
" Add support for repeating plugin commands.
Plug 'tpope/vim-repeat'
" rhubarb.vim: GitHub extension for fugitive.vim
Plug 'tpope/vim-rhubarb'
" scriptease.vim: A Vim plugin for Vim plugins
Plug 'tpope/vim-scriptease'
" speeddating.vim: use CTRL-A/CTRL-X to increment dates, times, and more
Plug 'tpope/vim-speeddating'
" surround.vim: quoting/parenthesizing made simple
Plug 'tpope/vim-surround'
" unimpaired.vim: Pairs of handy bracket mappings
Plug 'tpope/vim-unimpaired'
" Kotlin plugin for Vim. Featuring: syntax highlighting, basic indentation, Syntastic support
" Superseded by polyglot
" Plug 'udalov/kotlin-vim'
" VimOutliner is an outline processor with many of the same features as
" Grandview, More, Thinktank, Ecco, etc. Features include tree
" expand/collapse, tree promotion/demotion, level sensitive colors,
" interoutline linking, and body text.
Plug 'vimoutliner/vimoutliner'
" Vim/Ruby Configuration Files
" Superseded by polyglot
" Plug 'vim-ruby/vim-ruby'
" Help folks to align text, eqns, declarations, tables, etc
Plug 'vim-scripts/Align'
" Most Recently Used (MRU) Vim Plugin
Plug 'yegappan/mru'
let MRU_File = '~/vim/mru_files'
let MRU_Max_Entries = 1000
let MRU_Add_Menu = 0
" Vim plugin for easily moving text selections around
Plug 'zirrostig/vim-schlepp'
" Map ctrl-h/j/k/l in visual mode to drag the block.
vmap <C-h> <Plug>SchleppUp
vmap <C-l> <Plug>SchleppDown
vmap <C-k> <Plug>SchleppLeft
vmap <C-j> <Plug>SchleppRight
vmap ,d <Plug>SchleppDup
" Plug 'twitvim/twitvim'
" Plug 'file:///Users/pcheah/proj/twitvim'
call plug#end()
" ===== Other Initialization ===== {{{2
" Make filetype.vim treat .h files as C files.
" let c_syntax_for_h=1
" runtime! ftdetect/*.vim
runtime macros/matchit.vim
" Make vimpager use MacVim.
" Assuming that .vimpagerrc sources this file.
let g:vimpager_use_gvim = 1
" ----- GUI customization ----- {{{1
if has('gui_gtk') && has('gui_running')
" Workaround for gx command failing silently in gvim.
" https://vi.stackexchange.com/questions/5032/gx-not-opening-url-in-gvim-but-works-in-terminal
let g:netrw_browsex_viewer="setsid xdg-open"
endif
" In vim 5.4 with GTK+, the .font resource does not work.
" if has('gui_gtk') && has('gui_running')
" function! <SID>SetGuiFont()
" let str = 'set guifont=0xProto\ Nerd\ Font\ FONTSIZE,CommitMono\ Nerd\ Font\ Mono\ FONTSIZE,DejaVu\ Sans\ Mono\ FONTSIZE,7x14bold'
" execute substitute(str, 'FONTSIZE', s:font_size, 'g')
" endfunction
" function! <SID>ChangeGuiFontSize(incr)
" let s:font_size += a:incr
" if s:font_size < 14
" let s:font_size = 14
" endif
" if s:font_size > 30
" let s:font_size = 30
" endif
" call <SID>SetGuiFont()
" redraw
" echo 'Font size set to ' . s:font_size
" endfunction
" function! <SID>ResetGuiFontSize()
" let s:font_size = 16
" call <SID>SetGuiFont()
" endfunction
" " Ctrl-minus, ctrl-equals to decr/incr font size. Ctrl-zero to reset it.
" nnoremap <C-0> :call <SID>ResetGuiFontSize()<cr>
" nnoremap <C-_> :call <SID>ChangeGuiFontSize(-1)<cr>
" nnoremap <C-=> :call <SID>ChangeGuiFontSize(1)<cr>
" call <SID>ResetGuiFontSize()
" endif
if (has('win32') || has('win64')) && has('gui_running')
" Disable middle mouse paste in win32 GUI. That is very annoying with a
" wheel mouse.
noremap <MiddleMouse> <Nop>
lnoremap <MiddleMouse> <Nop>
noremap <2-MiddleMouse> <Nop>
lnoremap <2-MiddleMouse> <Nop>
noremap <3-MiddleMouse> <Nop>
lnoremap <3-MiddleMouse> <Nop>
noremap <4-MiddleMouse> <Nop>
lnoremap <4-MiddleMouse> <Nop>
" Special font for the Windows GUI.
set guifont=Fixedsys:h9
endif
if has('mac') && has('gui_running')
" Special font for the Mac
if hostname() =~? '^donhaven'
" Use smaller font on my laptop.
" set guifont=monaco:h13
set guifont=CascadiaMonoPL-Regular:h13
set linespace=2
if has("gui_macvim")
set macthinstrokes
endif
else
" set guifont=monaco:h14
set guifont=CascadiaMonoPL-Regular:h14
set linespace=2
if has("gui_macvim")
set macthinstrokes
endif
endif
endif
if has('mac')
" Map cmd-1 thru cmd-9 to switch tabs.
nnoremap <silent> <D-1> :silent! 1tabnext<cr>
nnoremap <silent> <D-2> :silent! 2tabnext<cr>
nnoremap <silent> <D-3> :silent! 3tabnext<cr>
nnoremap <silent> <D-4> :silent! 4tabnext<cr>
nnoremap <silent> <D-5> :silent! 5tabnext<cr>
nnoremap <silent> <D-6> :silent! 6tabnext<cr>
nnoremap <silent> <D-7> :silent! 7tabnext<cr>
nnoremap <silent> <D-8> :silent! 8tabnext<cr>
nnoremap <silent> <D-9> :silent! tablast<cr>
else
" Some mappings borrowed from macmap in vim source code.
" See https://github.com/vim/vim/blob/master/runtime/macmap.vim
" Map alt-t to open a tab.
nnoremap <silent> <A-t> :silent! tabnew<cr>
" Map alt-w to close a window.
nnoremap <silent> <A-w> :confirm close<cr>
" Map ctrl-s / alt-s to save the file.
nnoremap <silent> <C-s> :confirm write<cr>
nnoremap <silent> <A-s> :confirm write<cr>
imap <A-s> <C-o><A-s>
" Map alt-a to select all.
nnoremap <silent> <A-a> :if &selectmode != ""<Bar>execute ":norm gggH<C-O>G"<Bar> else<Bar>exe ":norm ggVG"<Bar>endif<CR>
vmap <A-a> <Esc><A-a>
imap <A-a> <Esc><A-a>
cmap <A-a> <C-C><A-a>
omap <A-a> <Esc><A-a>
" Map alt-1 thru alt-9 to switch tabs.
nnoremap <silent> <A-1> :silent! 1tabnext<cr>
nnoremap <silent> <A-2> :silent! 2tabnext<cr>
nnoremap <silent> <A-3> :silent! 3tabnext<cr>
nnoremap <silent> <A-4> :silent! 4tabnext<cr>
nnoremap <silent> <A-5> :silent! 5tabnext<cr>
nnoremap <silent> <A-6> :silent! 6tabnext<cr>
nnoremap <silent> <A-7> :silent! 7tabnext<cr>
nnoremap <silent> <A-8> :silent! 8tabnext<cr>
nnoremap <silent> <A-9> :silent! tablast<cr>
vnoremap <special> <A-x> "+x
vnoremap <special> <A-c> "+y
cnoremap <special> <A-c> <C-Y>
nnoremap <special> <A-v> "+gP
cnoremap <special> <A-v> <C-R>+
execute 'vnoremap <script> <special> <A-v>' paste#paste_cmd['v']
execute 'inoremap <script> <special> <A-v>' paste#paste_cmd['i']
endif
" If the gvim window is too small, try setting it larger.
if &lines < 30 && has('gui_running')
set lines=30
endif
" ----- Hotkey Customization ----- {{{1
" shift-insert will now paste text from clipboard
nnoremap <S-Insert> "*P
vnoremap <S-Insert> "-d"*P
noremap! <S-Insert> <C-R><C-R>*
vnoremap <C-Insert> "*y
vnoremap <S-Delete> "*d
vnoremap <C-Delete> "*d
" ctrl-tab, ctrl-shift-tab moves between tabs
nnoremap <C-Tab> gt
vnoremap <C-Tab> gt
nnoremap <C-S-Tab> gT
vnoremap <C-S-Tab> gT
" Map ctrl-h/j/k/l to move to other windows.
" Idea borrowed from spf13-vim. (http://vim.spf13.com/)
nnoremap <C-h> <C-W>h
nnoremap <C-l> <C-W>l
nnoremap <C-k> <C-W>k
nnoremap <C-j> <C-W>j
" Turn off F1 help key
nnoremap <F1> <NOP>
inoremap <F1> <NOP>
" F3 toggles no-linebreak mode
nnoremap <F3> :call <SID>Toggle_no_lbr()<cr>
" F4 toggles list mode
nnoremap <F4> :set invlist list?<cr>
vnoremap <F4> <esc>:set invlist list?<cr>gv
inoremap <F4> <C-o>:set invlist list?<cr>
" F5 toggles paste mode
nnoremap <F5> :set invpaste paste?<CR>
vnoremap <F5> <esc>:set invpaste paste?<CR>gv
" pastetoggle key in vim 5.4 allows us to get out of paste mode
" even from within insert mode.
inoremap <F5> <C-O>:set invpaste<CR>
set pastetoggle=<F5>
" Map F6 key to go to the next buffer and Shift-F6 to go to the previous
" buffer.
nnoremap <F6> :bnext<CR>
nnoremap <S-F6> :bprevious<CR>
" Ctrl-F8 toggles syntax coloring on and off
nnoremap <C-F8> :call <SID>Toggle_syntax()<cr>
" Shift-F8 will show syntax item at cursor
nnoremap <S-F8> :echo synIDattr(synID(line("."), col("."), 1), "name")<CR>
" F9 will toggle taglist.
" nnoremap <silent> <F9> :TlistToggle<cr>
" let Tlist_Process_File_Always = 1
" let Tlist_Use_Right_Window = 1
" let Tlist_Inc_Winwidth = 0
" let Tlist_Show_Menu = 1
" Ctrl-F9 toggles full height mode
nnoremap <C-F9> :call <SID>Toggle_full_height()<cr>
" F11 c: change current directory to the directory in which the current
" file resides.
nnoremap <F11>c :cd <C-R>=expand("%:p:h")<cr><cr>
" F11 h: startup directory (home)
let s:startdir=getcwd()
function! <SID>GetStartDir()
return s:startdir
endfunction
nnoremap <F11>h :execute "cd" '<c-r>=<SID>GetStartDir()<cr>'<cr>:pwd<cr>
" F12 a runs tal on the current paragraph or visual range.
" F12 A does the same thing but waits for user to type in arguments.
" nnoremap <F12>a {!}tal<cr>
" vnoremap <F12>a !tal<cr>
" nnoremap <F12>A {!}tal<space>
" vnoremap <F12>A !tal<space>
" F12 b runs boxes on the current paragraph or visual range.
" F12 B does the same thing but waits for user to type in arguments.
nnoremap <F12>b {!}boxes<cr>
vnoremap <F12>b !boxes<cr>
nnoremap <F12>B {!}boxes<space>
vnoremap <F12>B !boxes<space>
" F12 c runs ctags in the current file's directory.
" nnoremap <F12>c :call <SID>Run_ctags()<cr>
" F12 d removes all buffers.
nnoremap <F12>d :call <SID>Del_all_buf()<cr>
" F12 e: edit another file in the same directory as the current file.
set wildcharm=<c-z>
nnoremap <F12>e :e <C-R>=expand("%:p:h")."/"<cr><c-z><s-tab>
" F12 g converts coordinates from N ddd mm.mmm W ddd mm.mmm to
" dd.ddddd -dd.ddddd
" nnoremap <f12>g :call <SID>ConvertCoords()<cr>
" F12 g opens Fugitive in vertical split mode
nnoremap <f12>g :vertical Git<cr>
" F12 l updates a 'Last up-dated:' line
" Need to use a [s] here so that this macro won't change itself if
" invoked on this file.
let s:m = '1G/La[s]t updated:/e+0<CR>a <C-R>=<SID>Date_string()<CR><CR><ESC>dd'
execute 'nnoremap <F12>l' s:m
unlet s:m
" F12 m runs Marked on the Markdown file.
" function! s:Run_marked()
" silent !open -a "Marked 2" %
" redraw!
" endfunction
" augroup markdown_auto
" autocmd!
" autocmd FileType markdown nnoremap <buffer> <F12>m :call <SID>Run_marked()<cr>
" augroup END
" F12 p runs par on the current paragraph or visual range
" F12 P does the same thing but waits for user to type in arguments.
nnoremap <F12>p {!}par<cr>
vnoremap <F12>p !par<cr>
nnoremap <F12>P {!}par<space>
vnoremap <F12>P !par<space>
" F12 s inserts a date stamp.
" F12 s in visual mode replaces the selection with a date stamp.
nnoremap <F12>s i<C-R>=<SID>Date_string()<CR><ESC>
vnoremap <F12>s c<C-R>=<SID>Date_string()<CR><ESC>
inoremap <F12>s <C-R>=<SID>Date_string()<CR>
" F12 u: This mapping will format any bullet list. It requires
" that there is an empty line above and below each list entry. The
" expression commands are used to be able to give comments to the
" parts of the mapping. (from the vim tips file)
let s:m = ':noremap <f12>u :set ai<CR>' " need 'autoindent' set
let s:m = s:m . '{O<Esc>' " add empty line above item
let s:m = s:m . '}{)^W' " move to text after bullet
let s:m = s:m . 'i <CR> <Esc>' " add space for indent
let s:m = s:m . 'gq}' " format text after the bullet
let s:m = s:m . '{dd' " remove the empty line
let s:m = s:m . '5lDJ' " put text after bullet
execute s:m |" define the mapping
unlet s:m
" F12 ve edits .vimrc file
" F12 vs sources .vimrc file
nnoremap <F12>ve :edit $MYVIMRC<cr>
nnoremap <F12>vs :source $MYVIMRC<cr>
" F12 x runs boxes -r on the current paragraph or visual range.
" F12 X does the same thing but waits for user to type in arguments.
nnoremap <F12>x {!}boxes -r<cr>
vnoremap <F12>x !boxes -r<cr>
nnoremap <F12>X {!}boxes -r<space>
vnoremap <F12>X !boxes -r<space>
" iTerm2 sends nul characters for anti-idle. Ignore those characters in
" text mode.
if has('mac') && !has('gui_running')
inoremap <C-@> <Nop>
cnoremap <C-@> <Nop>
lnoremap <C-@> <Nop>
endif
" Allow saving of files as sudo when I forgot to start vim using sudo.
" See: http://stackoverflow.com/questions/2600783/how-does-the-vim-write-with-sudo-trick-work
cmap w!! w !sudo tee > /dev/null %
" Replace words with gn command.
nnoremap ,x *``cgn
nnoremap ,X #``cgN
" Clean up nbsp characters.
function! s:clean_nbsp()
call setline('.', substitute(getline('.'), '\%xa0', ' ', 'g'))
endfunction
command! -range=% CleanNBSP :<line1>,<line2>call s:clean_nbsp()
" ----- Vim Scripts ----- {{{1
" ===== Toggle syntax ===== {{{2
" Initialize all highlights that have nothing to do with syntax.
function! s:Highlight_Init()
highlight StatusLine gui=bold guifg=yellow guibg=#505050
highlight StatusLineNC gui=NONE guifg=yellow guibg=#505050
highlight User1 term=inverse cterm=inverse
highlight User1 gui=NONE guifg=green guibg=#505050
highlight SignColumn ctermbg=black ctermfg=Cyan guibg=black guifg=Cyan
" color customizations
highlight Normal guifg=Gray guibg=black ctermfg=Gray ctermbg=black
highlight Cursor ctermfg=black ctermbg=gray guifg=black guibg=gray
highlight ModeMsg guifg=gray guibg=black ctermfg=gray ctermbg=black
highlight MoreMsg guifg=LightGreen guibg=black ctermfg=LightGreen ctermbg=black
highlight Question guifg=LightGreen guibg=black ctermfg=LightGreen ctermbg=black
highlight Directory guifg=LightBlue guibg=black ctermfg=Cyan ctermbg=black
highlight NonText guifg=Yellow guibg=black ctermfg=Yellow ctermbg=black
highlight SpecialKey guifg=Magenta guibg=black ctermfg=Magenta ctermbg=black
highlight CursorLine term=underline cterm=NONE ctermfg=white ctermbg=darkblue gui=NONE guifg=white guibg=blue
highlight Visual term=reverse cterm=NONE ctermfg=black ctermbg=cyan gui=NONE guifg=black guibg=#32CED7
highlight IncSearch term=reverse cterm=NONE ctermfg=black ctermbg=cyan gui=NONE guifg=black guibg=#32CED7
highlight SpellCap term=reverse cterm=NONE ctermfg=white ctermbg=darkblue gui=undercurl guisp=blue
highlight SpellBad term=reverse cterm=NONE ctermfg=white ctermbg=darkred gui=undercurl guisp=red
highlight SpellLocal term=reverse cterm=NONE ctermfg=white ctermbg=darkyellow gui=undercurl guisp=green
highlight SpellRare term=reverse cterm=NONE ctermfg=white ctermbg=darkmagenta gui=undercurl guisp=magenta
if v:version >= 700
highlight MatchParen guifg=Yellow guibg=DarkGreen ctermfg=Yellow ctermbg=DarkGreen
" Popup menu colors.
highlight PMenu ctermfg=White ctermbg=DarkBlue guifg=Gray guibg=#513692
highlight PMenuSel ctermfg=White ctermbg=Brown guifg=Gray guibg=#824C21
highlight PMenuSbar ctermfg=White ctermbg=Brown guifg=Gray guibg=#824C21
highlight PMenuThumb ctermfg=Black ctermbg=Gray guifg=Black guibg=Gray
endif
" Customize folding colors.
highlight Folded guifg=LightCyan guibg=bg
highlight FoldColumn guifg=LightCyan guibg=bg
highlight Folded ctermfg=LightCyan ctermbg=bg
highlight FoldColumn ctermfg=LightCyan ctermbg=bg
endfunction
" The syntax on command resets all custom syntax highlights. So we
" define a function to turn the syntax highlighting on and restore the
" custom highlights.
function! s:Turn_syntax_on()
unlet! g:colors_name
syntax on
" Set colors_name so MacVim's default colorscheme doesn't override our
" colors.
let g:colors_name='vimrc'
highlight Comment guifg=orange ctermfg=Yellow
highlight PreProc guifg=Magenta ctermfg=LightMagenta
highlight Statement guifg=LightGreen ctermfg=LightGreen gui=NONE
highlight Delimiter guifg=Yellow ctermfg=Yellow
highlight Special guifg=Red ctermfg=LightRed
highlight Type guifg=Cyan ctermfg=Cyan gui=NONE
highlight Identifier guifg=LightCyan ctermfg=LightCyan
if has('mac')
highlight Identifier guifg=Cyan ctermfg=LightCyan
endif
" Set the html_my_rendering variable so that html.vim won't clobber
" our html highlight settings.
let g:html_my_rendering=1
highlight htmlLink term=underline
highlight htmlLink cterm=underline ctermfg=yellow
highlight htmlLink gui=underline guifg=yellow
highlight htmlBold term=bold cterm=bold gui=bold
highlight htmlBoldUnderline term=bold,underline
highlight htmlBoldUnderline cterm=bold,underline ctermfg=yellow
highlight htmlBoldUnderline gui=bold,underline guifg=yellow
highlight htmlBoldItalic term=bold
highlight htmlBoldItalic cterm=bold,italic ctermfg=lightgreen
highlight htmlBoldItalic gui=bold guifg=lightgreen
highlight htmlBoldUnderlineItalic term=bold,underline
highlight htmlBoldUnderlineItalic cterm=bold,underline