-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc_main
1545 lines (1261 loc) · 49.5 KB
/
vimrc_main
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
""" SETTINGS
set nocompatible " Don't need to keep compatibility with Vi
filetype plugin indent on " enable detection, plugins and indenting in one step
syntax on " Turn on syntax highlighting
set synmaxcol=1000 " Don't try to highlight lines longer than 1000 characters
set showcmd " show incomplete cmds down the bottom
set noshowmode " don't show current mode down the bottom (set showmode does the opposite)
set showmatch " Set show matching parenthesis
set noexrc " Don't use the local config
set virtualedit=all " Allow the cursor to go in to 'invalid' places
set incsearch " Find the next match as we type the search
set hlsearch " Hilight searches by default
set ignorecase " Ignore case when searching
set smartcase " ...unless they contain at least one capital letter
set shiftwidth=2 " Number of spaces to use in each autoindent step
set shiftround " When at 3 spaces, and I hit > ... go to 4, not 5
set tabstop=2 " Two tab spaces
set softtabstop=2 " Number of spaces to skip or insert when <BS>ing or <Tab>ing
set expandtab " Spaces instead of tabs for better cross-editor compatibility
set smarttab " Use shiftwidth and softtabstop to insert or delete (on <BS>) blanks
set nowrap " No wrapping
set copyindent " Copy the previous indentation on autoindenting
set backspace=indent,eol,start " Allow backspacing over everything in insert mode
set noerrorbells " Don't make noise
set wildmenu " Make tab completion act more like bash
set wildmode=list:longest " Tab complete to longest common string, like bash
" set mouse-=a " Disable mouse automatically entering visual mode
set mouse=a " Enable mouse support in the terminal VIM and activate visual mode with dragging
if !has('nvim')
set ttymouse=xterm2 " Allow resizing of Vim splits inside tmux. See https://superuser.com/a/550482/648584
set ttyscroll=3 " Prefer redraw to scrolling for more than 3 lines TODO: see if I like this
endif
set bs=2 " This influences the behavior of the backspace option. See :help 'bs' for more details
set number " Show line numbers
set cmdheight=2 " Make the command line a little taller to hide 'press enter to viem more' text
set ttyfast " Improves screen redraw
set lazyredraw " Avoid redrawing the screen mid-command.
set splitbelow " New splits will be created below the current split
set splitright " New splits will be created to the right of the current split
set confirm " Ask to save changes
set encoding=utf-8 " Set utf-8 encoding
set pastetoggle=<F2> " Press F2 in insert mode to preserve tabs when pasting from clipboard into terminal
set updatetime=300 " Should 'fix' git-gutter weird highlighting issues
set notimeout ttimeout ttimeoutlen=10 "Quckly time out on keycodes, but never time out on mappings
set switchbuf=useopen,usetab "Attempt to edit currently open files instead of opening multiple buffers. TODO: possibly turn this off
set modelineexpr
" TEST for react gf
set path=.,src
set suffixesadd=.js,.jsx
function! LoadMainNodeModule(fname)
let nodeModules = "./node_modules/"
let packageJsonPath = nodeModules . a:fname . "/package.json"
if filereadable(packageJsonPath)
return nodeModules . a:fname . "/" . json_decode(join(readfile(packageJsonPath))).main
else
return nodeModules . a:fname
endif
endfunction
set includeexpr=LoadMainNodeModule(v:fname)
" END Test for react gf
runtime macros/matchit.vim "Extend % for matching brackets, if/end, and more
set wildignore+=*/production_data/*,*/db/dumps/*,*/coverage/*,*/accredited_investor_questionnaires/*,*/accredited_verification_pdfs/*,*/HTML_DEMOS/*,*/docusign_docs/*,*/cookbooks/*,*/public/uploads/*,*/public/images/*,*/vim_sessions/*,*/node_modules/*,*/bower_components/*,*/tmp/*,*.so,*.swp,*.zip,*/sassdoc/* " MacOSX/Linux
let mapleader = "," "remap leader to ',' which is much easier than '\'
let maplocalleader = "\\" "add a local leader of '\'
" Reveal in Finder - opens finder to the folder of the file that is currently open
command! Rif execute '!open %:p:h'
""" UNMAPS
" Disable the <S> command in normal mode which substitutes the whole line after a motion.
nmap S <nop>
" STOP the help from popping up with the F1 key.
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
""" SPELLING
" Toggle spellcheck with F6 (highlighted and underlined in stark WHITE)
" ---------------------------------------------------------------------
" z= - view spelling suggestions for a misspelled word
" zg - add word to dictionary
" zug - undo add word to dict
hi SpellBad cterm=underline ctermfg=white
nn <F6> :setlocal spell! spell?<CR>
" FIXME: figure out which spelling to keep
" Spelling
hi SpellBad ctermfg=009 ctermbg=001 guifg=#ff0000 guibg=#ffffff
hi SpellCap ctermfg=009 ctermbg=001 guifg=#ff0000 guibg=#ffffff
" Open the word under the cursor in the macOS Dictionary with F11
map <F11> "dyiw:call MacDict(@d)<CR>
""" CLIPBOARD
if has('nvim')
" Use unnamed registers for clipboard
set clipboard+=unnamedplus
else
" This allows you to share Vim's clipboard with OS X.
set clipboard=unnamed
endif
if has("unix")
let s:uname = system("uname")
if s:uname == "Linux\n"
" Remote Clipboard
function! PropagatePasteBufferToOSX()
let @n=getreg('"')
call system('pbcopy-remote', @n)
echo "done"
endfunction
function! PopulatePasteBufferFromOSX()
let @" = system('pbpaste-remote')
echo "done"
endfunction
nnoremap <leader>3 :call PopulatePasteBufferFromOSX()<cr>
nnoremap <leader>2 :call PropagatePasteBufferToOSX()<cr>
nnoremap yy yy:call PropagatePasteBufferToOSX()<cr>
function! YRRunAfterMaps()
nnoremap Y :<C-U>YRYankCount 'y$'<CR> <bar> :call PropagatePasteBufferToOSX()<CR>
vnoremap y y:call PropagatePasteBufferToOSX()<CR>
endfunction
endif
endif
""" COLORS & THEMES & BUFFER DISPLAY
if has("unix")
let s:uname = system("uname")
if s:uname != "Darwin\n"
set t_Co=256 "256 colors support
let g:solarized_termcolors=16
endif
endif
if has('termguicolors') && !has('gui_running')
set termguicolors
endif
let g:solarized_termtrans=1
set background=dark
" set background=light
colorscheme solarized8
" TMUX helper for solarized8
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
" Right column guide
set colorcolumn=81
" Right column guide (git commit message)
au BufNewFile,BufRead COMMIT_EDITMSG setlocal colorcolumn=51
" Cursor
" This switches the cursor into a pipe when in insert mode tmux will only
" forward escape sequences to the terminal if surrounded by a DCS sequence
if has('nvim')
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
else
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
endif
if has("gui_macvim")
set guifont=Monaco\ for\ Powerline:h12
endif
" TODO: (2018-02-24) jon => decide if I still want this
set statusline=%F%m%r%h%w[%L][%{&ff}]%y[%p%%][%04l,%04v]
" | | | | | | | | | | |
" | | | | | | | | | | + current
" | | | | | | | | | | column
" | | | | | | | | | +-- current line
" | | | | | | | | +-- current % into file
" | | | | | | | +-- current syntax in
" | | | | | | | square brackets
" | | | | | | +-- current fileformat
" | | | | | +-- number of lines
" | | | | +-- preview flag in square brackets
" | | | +-- help flag in square brackets
" | | +-- readonly flag in square brackets
" | +-- modified flag in square brackets
" +-- full path to file in the buffer
" Show line endings and tabs (whitespace markers)
nmap <leader>il :set list!<CR>
" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬
" toggle hide numbers
map <leader>1 :set nonumber! number?<CR>
" toggle relative numbers
function! NumberToggle()
if(&relativenumber == 1)
set norelativenumber
set number
else
set relativenumber
endif
endfunc
nnoremap <leader>l :call NumberToggle()<CR>
" Indent guides turned on with <leader>ig
let g:indent_guides_start_level=1
let g:indent_guides_guide_size=1
" Airline
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_buffers = 0
let g:airline_powerline_fonts = 1
let g:airline_detect_iminsert = 1
" tmux plugin for vim-airline https://github.com/edkolev/tmuxline.vim
let g:tmuxline_preset = 'full'
" Signify
"let g:signify_sign_color_guibg = '#032b36'
let g:signify_sign_color_inherit_from_linenr = 1
let g:signify_sign_weight = 'NONE'
let g:signify_update_on_bufenter = 1
""" NERDTree
" Open NERDTree with [<leader>d]
map <Leader>d :NERDTreeMirrorToggle<CR>
" Show current file in the NERDTree hierarchy
map <Leader>D :NERDTreeFind<CR>
let NERDTreeMinimalUI=1
let NERDTreeDirArrows=1
let NERDTreeWinSize = 51
let NERDTreeShowLineNumbers=1
let g:nerdtree_tabs_focus_on_files=1
let g:nerdtree_tabs_open_on_console_startup=1
let g:nerdtree_tabs_smart_startup_focus=2
" list of file types I don't want to auto-open nerdtree for
autocmd FileType vim,tmux,gitcommit,gitconfig,gitrebase let g:nerdtree_tabs_open_on_console_startup=0
autocmd BufNewFile,BufRead vundle let g:nerdtree_tabs_open_on_console_startup=0
let NERDSpaceDelims=1 " For nerdcommenter, add one space after comment char
""" FUZZY FIND
nnoremap <C-f> :FZF<CR>
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-i': 'split',
\ 'ctrl-v': 'vsplit' }
"""" Ack in Project
" AckG matches file names in the project, regular Ack looks inside those files
map <Leader><C-t> :AckG<space>
let g:ackprg = 'ag'
" Split rightward so as not to displace a left NERDTree
let g:ack_mappings = {
\ 'v': '<C-W><CR><C-W>L<C-W>p<C-W>J<C-W>p',
\ 'gv': '<C-W><CR><C-W>L<C-W>p<C-W>J',
\ '<cr>': ':NERDTreeMirrorToggle<CR><CR>:NERDTreeMirrorToggle<CR><C-W>l' }
nnoremap <Leader><C-f> :tabnew <Bar> Ack!<Space>
""" VIMWIKI
let wiki0 = {}
let wiki0.path = '~/vimwiki/'
let wiki0.path_html = '~/vimwiki_html/'
let wiki0.auto_toc = 1
let wiki1 = {}
let wiki1.path = '~/vimwiki_headway/'
let wiki1.path_html = '~/vimwiki_headway_html/'
let wiki1.auto_toc = 1
" Run multiple wikis
let g:vimwiki_list = [wiki0, wiki1]
au BufRead,BufNewFile *.wiki set filetype=vimwiki
" Open diary with \d
:autocmd FileType vimwiki map <localleader>d :VimwikiMakeDiaryNote<CR>:Calendar<CR>
au! BufRead ~/vimwiki_headway/index.wiki !cd ~/vimwiki_headway;git pull
" au! BufWritePost ~/vimwiki_headway/* !cd ~/vimwiki_headway;git add -A;git commit -m "Auto commit + push.";git push
" let g:vimwiki_folding='expr'
""" SPLIT AND BUFFER MANAGEMENT
" Resize splits when the window is resized
au VimResized * :wincmd =
" Better split management, kept in sync with tmux' mappings of (<prefix>| and <prefix>-)
noremap <leader>- :sp<CR><C-w>j
noremap <leader>\| :vsp<CR><C-w>l
" Allow resizing splits with +/_ for down(bigger) / up(smaller) and ALT-=(bigger)/ALT–(smaller). Repeatable w/hold.
if bufwinnr(1)
" Alt =
map ≠ <C-W>>
" Alt -
map – <C-W><
map _ <C-W>-
map + <C-W>+
endif
" Adjusts all buffers to the same size
map <Leader>= <C-w>=
" Open splits from quickfix window like you can in ctrl-p
let g:qfenter_vopen_map = ['<C-v>']
let g:qfenter_hopen_map = ['<C-CR>', '<C-s>', '<C-x>', '<C-i>']
let g:qfenter_topen_map = ['<C-t>']
let g:eighties_bufname_additional_patterns = ['fugitiveblame','locationlist'] " Don't try to auto-resize a fugitive blame split to 80 chars
noremap <F5> :redraw!<cr>
""" SEARCH & FIND & REPLACE
"Search and replace the word under the cursor with whatever you type in
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/
"Search and replace only within a given selection. This DOES NOT replace all
" instances on the line that the highlight is on, which is why it's awesome.
vnoremap <Leader>S :s/\%V//g<Left><Left><Left>
" Better search with insearch
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
" Turn highlighting off after a search (and / or turn off highlights)
noremap <silent> <leader><space> :noh<cr>:call clearmatches()<cr>
" Keeps cursor on star search highlight
let g:indexed_search_dont_move=1
" http://vim.wikia.com/wiki/Make_search_results_appear_in_the_middle_of_the_screen
nnoremap <silent> <F4> :call <SID>SearchMode()<CR>
function! s:SearchMode()
" if !exists('s:searchmode') || s:searchmode == 0
if !exists('s:searchmode') || s:searchmode == 2
echo 'Search next: scroll hit to middle if not on same page'
nnoremap <silent> n n:call <SID>MaybeMiddle()<CR>
nnoremap <silent> N N:call <SID>MaybeMiddle()<CR>
let s:searchmode = 1
" elseif s:searchmode == 1
else
echo 'Search next: scroll hit to middle'
nnoremap n nzz
nnoremap N Nzz
let s:searchmode = 2
" else
" echo 'Search next: normal'
" nunmap n
" nunmap N
" let s:searchmode = 0
endif
endfunction
" If cursor is in first or last line of window, scroll to middle line.
function! s:MaybeMiddle()
if winline() == 1 || winline() == winheight(0)
normal! zz
endif
endfunction
augroup searchmode
au!
au BufRead * call s:SearchMode()
augroup END
""" SESSION MANAGEMENT AND OPENING FILES
" Create new session
nmap SC :Obsess ~/.vim/sessions/
" Open the last saved session
nmap SO :so ~/.vim/sessions/
nmap SQ :Obsess!<CR>
" OpenChangedFiles COMMAND
" Open a split for each dirty (or new) file in git
" Shamelessly stolen from Gary Bernhardt: https://github.com/garybernhardt/dotfiles
function! OpenChangedFiles()
only " Close all windows, unless they're modified
let modified_status = system('git status -s | grep "^ \?\(M\|A\)" | cut -d " " -f 3')
let added_status = system('git status -s | grep "^ \?\(??\)" | cut -d " " -f 2')
let status = modified_status . added_status
let filenames = split(status, "\n")
if len(filenames) > 0
exec "edit " . filenames[0]
for filename in filenames[1:]
exec "tabedit " . filename
endfor
end
endfunction
command! OpenChangedFiles :call OpenChangedFiles()
" nnoremap ,em :NERDTreeMirrorToggle<CR>:OpenChangedFiles<CR>:NERDTreeMirrorToggle<CR>
nnoremap ,em :OpenChangedFiles<CR>
function! OpenLastCommitFiles()
only " Close all windows, unless they're modified
let status = system('git log --pretty=format: --name-only --no-merges -n 1')
let filenames = split(status, "\n")
if len(filenames) > 0
exec "edit " . filenames[0]
for filename in filenames[1:]
exec "tabedit " . filename
endfor
end
endfunction
command! OpenLastCommitFiles :call OpenLastCommitFiles()
nnoremap ,elc :OpenLastCommitFiles<CR>
" Make sure Vim returns to the same line when you reopen a file.
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
""" SAVING FILES AND BUFFERS
" Hit SS in insert or normal mode to save
noremap SS :w<CR>
inoremap SS <Esc>:w<CR>
" Force save the current file even if you don't have permission
map W!! :w !sudo tee % > /dev/null<CR>
cmap w!! w !sudo tee % >/dev/null
" autoread and autowrite http://albertomiorin.com/blog/2012/12/10/autoread-and-autowrite-in-vim/
augroup save
au!
au FocusLost * wall
augroup END
set nohidden
set nobackup
set noswapfile
set nowritebackup
set autoread
set autowrite
set autowriteall
" Persistent-undo
set undodir=$HOME/.vim/undo
set undofile
" Allow for typing various quit cmds while accidentally capitalizing a letter
command! -bar Q quit "Allow quitting using :Q
command! -bar -bang Q quit<bang> "Allow quitting without saving using :Q!
command! -bar QA qall "Quit all buffers
command! -bar Qa qall "Quit all buffers
command! -bar -bang QA qall<bang> "Allow quitting without saving using :Q!
command! -bar -bang Qa qall<bang> "Allow quitting without saving using :Q!
" NOTE - the above has nothing to do with the quit commands below
" Make Q useful and avoid the confusing Ex mode.
" Pressing Q with this mapping does nothing intentionally
noremap Q <nop>
" Close window.
noremap QQ :q<CR>
" close and write
noremap WQ :wq<CR>
" Close all.
noremap QA :qa<CR>
" Close, damn you!
noremap Q! :q!<CR>
" ,q to toggle quickfix window (where you have stuff like GitGrep)
" ,oq to open it back up (rare)
nmap <silent> ,cq :cclose<CR>
nmap <silent> ,co :copen<CR>
" " TextEdit might fail if hidden is not set.
" TODO Jon, this conflicts with line 479, not sure what the implications are
" set hidden
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
set signcolumn=yes
let g:vista#renderer#enable_icon = 0
let g:vista_icon_indent = ["╰─▸ ", "├─▸ "]
highlight CocErrorVirtualText ctermfg=Red guifg=#ff0000
highlight CocWarningVirtualText ctermfg=Brown guifg=#ff922b
highlight CocInfoVirtualText ctermfg=Yellow guifg=#fab005`
highlight CocHintVirtualText ctermfg=Blue guifg=#15aabf`
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
if exists('*complete_info')
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current line.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Introduce function text object
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)
" Use <TAB> for selections ranges.
" NOTE: Requires 'textDocument/selectionRange' support from the language server.
" coc-tsserver, coc-python are the examples of servers that support it.
nmap <silent> <TAB> <Plug>(coc-range-select)
xmap <silent> <TAB> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
" TODO Jon, i think we are using airline? maybe do we need to do something different here?
" set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings using CoCList:
" Show all diagnostics.
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
nnoremap <silent> <space>v :<C-u>Vista coc<CR>
" With tmux-plugins/vim-tmux-focus-events, vim will load up a file on focus so write the file when switching away
let g:tmux_navigator_save_on_switch = 1
""" CTAGS
"Update CTags
nnoremap <silent> <leader>ct :!$(.git/hooks/ctags &)<cr> <bar> :redraw!<cr>
" ExCTags window (requires http://ctags.sourceforge.net/)
nmap <F8> :TagbarToggle<CR>
let g:tagbar_left = 1
let g:tagbar_autofocus = 1
let g:tagbar_compact = 1
let g:tagbar_autoclose = 1
" Open ctag in tab/vertical split
map <leader><C-\> :tab split<CR>:exec("tag ".expand("<cword>"))<CR>
map <C-\> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
" NOTE: Jump to previous file with <leader><C-^>
""" TABS
" Load up all buffers into tabs
nmap <localleader>bt :tab sball<CR>
" Switch to last active tab see https://stackoverflow.com/a/2120168/935514
let g:lasttab = 1
nmap <Leader>fl :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
" Close current tab
nmap <leader>fc :tabclose<CR>
" previous tab(shift-9), next tab (shift-0)
nnoremap ( :tabp<CR>
nnoremap ) :tabn<CR>
" switch tab order with Ctrl+<left>/<right>
map <Esc>[C :tabm +1<Esc>
map <Esc>[D :tabm -1<Esc>
function! MoveToPrevTab()
"there is only one window
if tabpagenr('$') == 1 && winnr('$') == 1
return
endif
"preparing new window
let l:tab_nr = tabpagenr('$')
let l:cur_buf = bufnr('%')
if tabpagenr() != 1
close!
if l:tab_nr == tabpagenr('$')
tabprev
endif
sp
else
close!
exe "0tabnew"
endif
"opening current buffer in new window
exe "b".l:cur_buf
endfunc
function! MoveToNextTab()
"there is only one window
if tabpagenr('$') == 1 && winnr('$') == 1
return
endif
"preparing new window
let l:tab_nr = tabpagenr('$')
let l:cur_buf = bufnr('%')
if tabpagenr() < tab_nr
close!
if l:tab_nr == tabpagenr('$')
tabnext
endif
sp
else
close!
tabnew
endif
"opening current buffer in new window
exe "b".l:cur_buf
endfunc
" switch tab order with Ctrl+<up>/<down>
map <Esc>[B :call MoveToNextTab()<CR>
map <Esc>[A :call MoveToPrevTab()<CR>
""" ALIGNMENT
"if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
nmap <localleader>a, :Tabularize /,\zs<CR>
vmap <localleader>a, :Tabularize /,\zs<CR>
" Triggers align of cucumber tables when you close it out with a | and have at
" least two lines. Thanks tpope :)
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
""" FOLDING
" toggle folding with za.
" fold everything with zM
" unfold everything with zR.
" zm and zr can be used too
" set foldmethod=syntax "fold based on syntax (except for haml below)
" set foldnestmax=10 "deepest fold is 10 levels
" set nofoldenable "dont fold by default
autocmd BufNewFile,BufRead *.haml setl foldmethod=indent nofoldenable
autocmd! FileType nofile setl foldmethod=indent nofoldenable
autocmd BufNewFile,BufRead vimrc_main setl foldmethod=syntax nofoldenable
set foldlevelstart=99
" Space to toggle folds.
nnoremap <Space> za
vnoremap <Space> za
" Toggles folds being enabled for this vim session
function! FoldToggle()
if(&foldenable == 1)
au WinEnter * set nofen
au WinLeave * set nofen
au BufEnter * set nofen
au BufLeave * set nofen
:set nofen
else
au WinEnter * set fen
au WinLeave * set fen
au BufEnter * set fen
au BufLeave * set fen
:set fen
endif
endfunc
nnoremap <Leader>nf :call FoldToggle()<CR>
""" CODE COVERAGE AND TESTING
"""" Coverage via Cadre/github.com/killphi/vim-legend
let g:legend_active_auto = 0
let g:legend_hit_color = "ctermfg=64 cterm=bold gui=bold guifg=Green"
let g:legend_ignored_sign = "◌"
let g:legend_ignored_color = "ctermfg=234"
let g:legend_mapping_toggle = '<Leader>cv'
let g:legend_mapping_toggle_line = '<localleader>cv'
"""" vim-rspec & cucumber test runner mappings <leader>T
let VimuxHeight = "33" "this is percentage
let VimuxOrientation = "h"
let VimuxUseNearestPane = 1
let g:turbux_command_prefix = 'clear;'
nmap <leader>t <Plug>SendTestToTmux
nmap <leader>T <Plug>SendFocusedTestToTmux
" for rspec.vim (syntax highlighting enhancements for rspec)
autocmd BufReadPost,BufNewFile *_spec.rb set syntax=rspec
"""" CodeClimate Bindings
nmap <Leader>aa :CodeClimateAnalyzeProject<CR>
nmap <Leader>ao :CodeClimateAnalyzeOpenFiles<CR>
nmap <Leader>af :CodeClimateAnalyzeCurrentFile<CR>
""" PLUGIN SETTINGS
" Set super tab to start completion with ctrl+j and move down the list with
" more j's, move back with ctrl+k
let g:SuperTabMappingForward = '<c-k>'
let g:SuperTabMappingBackward = '<c-j>'
" YankRing plugin to manage yanked/deleted buffers
nnoremap <silent> <F7> :YRShow<CR>
let g:yankring_history_file = '.yankring-history'
" let g:yankring_zap_keys = 'f F t T / ?'
" Dig through the tree of undo possibilities for your current file
nnoremap <F3> :GundoToggle<CR>
let g:gundo_right = 1
let g:gundo_preview_bottom=1
let g:gundo_preview_height = 40
" Gist settings for mattn/gist-vim
let g:gist_clip_command = 'pbcopy'
let g:gist_detect_filetype = 1
let g:gist_open_browser_after_post = 1
let g:gist_post_private = 1
" Buffrgator settings
let g:buffergator_viewport_split_policy="B"
let g:buffergator_split_size=10
let g:buffergator_suppress_keymaps=1
let g:buffergator_sort_regime = "mru"
map <Leader>b :BuffergatorToggle<cr>
" Vim-stripper: Stripe whitespace from the end of lines for all except .sql
let g:StripperIgnoreFileTypes = ['sql']
" reload current top window/tab of chrome
map <leader>rr :ChromeReload<CR>
let g:returnApp = "iTerm"
" Pull up the TODO And NOTE and FIXME definitions from the whole app
let g:TagmaTasksPrefix = '<localleader><localleader>t'
let g:TagmaTasksHeight = 10
map <Leader><Leader>tt :TagmaTasks * app/** config/** db/** doc/** features/** lib/** public/** spec/** test/** vendor/**<CR>
" Use deoplete (autocomplete) on startup
let g:deoplete#enable_at_startup = 1
let g:deoplete#enable_smart_case = 1
" deoplete.nvim
" inoremap <silent> <expr> <Tab> pumvisible() ? '\<C-n>' : deoplete#mappings#manual_complete()
" deoplete-ternjs
let g:deoplete#sources = {}
let g:deoplete#sources.javascript = ['ternjs']
" let g:deoplete#sources.gitcommit = ['github'] " currently broken https://github.com/SevereOverfl0w/deoplete-github/issues/5
" let g:deoplete#sources.ruby = ['solar']
let g:deoplete#omni#functions = {}
let g:deoplete#omni_patterns = {}
" tern_for_vim
let g:tern#command = ['tern']
let g:tern#arguments = ['--persistent']
let g:deoplete#omni#functions.javascript = ['tern#Complete']
let g:deoplete#omni_patterns.javascript = '\h\w*\|\h\w*\.\%(\h\w*\)\|[^. \t]\.\%(\h\w*\)'
" ruby
let g:deoplete#omni#functions.ruby = ['solar']
let g:deoplete#omni_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::'
"Add extra filetypes
let g:deoplete#sources#ternjs#filetypes = [
\ 'jsx',
\ 'javascript.jsx',
\ 'vue',
\ ]
" UltiSnips
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger="<c-tab>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
let g:UltiSnipsSnippetsDir='~/.vim/UltiSnips'
let g:ulti_expand_or_jump_res = 0
function! CleverTab()"{{{
call UltiSnips#ExpandSnippetOrJump()
if g:ulti_expand_or_jump_res
return ""
else
if pumvisible()
return "\<c-n>"
else
return "\<Tab>"
endif
endif
endfunction"}}}
inoremap <silent> <tab> <c-r>=CleverTab()<cr>
snoremap <silent> <tab> <esc>:call UltiSnips#ExpandSnippetOrJump()<cr>
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
map <leader>u :UltiSnipsEdit<cr>
if has("unix")
let s:uname = system("uname")
if s:uname == "Darwin\n"
" Do Mac stuff here
" Dash
"let g:dash_map = {
" \ 'ruby' : 'rails'
" \ }
au BufNewFile,BufRead *.rb :DashKeywords rails ruby<cr>
nmap <silent> <LocalLeader>d <Plug>DashSearch
nmap <silent> <LocalLeader>D <Plug>DashGlobalSearch
endif
endif
""" MARKDOWN & WRITING
map <localleader>m :MarkedOpen!<CR>
let g:marked_app = "Marked" " Need to specify v1 of the app
" let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_conceal = 0
let g:vim_markdown_frontmatter = 1
" Syntax highlight code in markdown files
let g:markdown_fenced_languages = ['javascript', 'js=javascript', 'json=javascript', 'ruby']
let g:vim_markdown_emphasis_multiline = 0
let g:vim_markdown_toc_autofit = 1
" Disable ]c for move to current header of vim-markdown
nmap <Plug>Markdown_MoveToCurHeader <Plug>Markdown_MoveToCurHeader
" function! s:Toc()
" if &filetype == 'markdown'
" :normal SS
" endif
" endfunction
" autocmd VimEnter *.m* call s:Toc()
" autocmd BufReadPost *.m* call s:Toc()
" autocmd BufWinEnter *.m* call s:Toc()
augroup ft_markdown
au!
au BufNewFile,BufRead *.m*down setlocal filetype=markdown foldlevel=1
" Use <localleader>1/2/3 to add headings.
au Filetype markdown nnoremap <buffer> <localleader>1 mzI# <ESC>
au Filetype markdown nnoremap <buffer> <localleader>2 mzI## <ESC>
au Filetype markdown nnoremap <buffer> <localleader>3 mzI### <ESC>
" au FileType markdown nnoremap <leader>al <Esc>`<i[<Esc>`>la](<Esc>"*]pa)<Esc>
"