-
Notifications
You must be signed in to change notification settings - Fork 7
/
.vimrc
1340 lines (1106 loc) · 45.3 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
"
" ,---.
" ,--. ,--.,--. | |
" \ `.' / `--',--,--,--.| .' Ches Martin
" \ / ,--.| || | http://chesmart.in
" \ / | || | | |`--'
" `-' `--'`--`--`--'.--.
" '--'
"
" In the extreme unlikelihood that anyone runs evim on my system,
" it will ignore all of this anyway.
if v:progname =~? "evim" | finish | endif
" Runtime + Plugin System Bootstrap {{{1
" --------------------------------------
" Vim sets $MYVIMRC, make it easy to get to stuff in ~/.vim too.
if has('nvim')
let $MYVIMRUNTIME = expand('<sfile>:p:h') " init.vim is child not sibling
else
let $MYVIMRUNTIME = expand('<sfile>:p:h') . '/.vim'
endif
if has('vim_starting')
" Vim, not Vi. This should be set first.
set nocompatible
set runtimepath+=~/.vim/bundle/neobundle.vim
endif
" Register and load plugins.
runtime include/bundles.vim
" Built-ins. Some things moved in recent Vim versions with package support.
if has('packages') && !has('nvim') " Neovim hasn't moved them yet
packadd! editexisting " Bring forward existing session w/ open file
packadd! matchit " More powerful % for if/fi, HTML tags, etc.
else
runtime macros/editexisting.vim
runtime macros/matchit.vim
endif
runtime ftplugin/man.vim " Sweet :Man command opens pages in split
" Allow plugins to work their magic.
filetype plugin indent on
" Check and prompt for any plugins pending installation.
NeoBundleCheck
" Options {{{1
" ------------
" Miscellaneous and Display {{{2
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" One place for backup and swap files, but we'll try a project-local .backup
" directory first if it exists. TODO: appropriate paths for Windows
let s:my_backups_rootdir = $HOME . '/.autosave/vim'
let s:my_swapfiles_dir = s:my_backups_rootdir . '/swap'
if !isdirectory(s:my_swapfiles_dir)
call mkdir(s:my_swapfiles_dir, 'p')
endif
" // make swap files unique based on path
set directory=./.backup//,~/.autosave/vim/swap//
set backup " keep a backup file
set backupdir=./.backup,~/.autosave/vim
set history=500 " keep more command line history
set ruler " show the cursor position all the time
set showcmd " display commands as they're being entered
set nomodeline " use securemodelines
set incsearch " do incremental searching
set ignorecase " Do case insensitive matching
set smartcase " But if search contains capitals, be sensitive
set gdefault " Line-global substitution by default, usually what you want
set scrolloff=3 " Keep some context visible when scrolling
set sidescrolloff=4
set wildmenu " Modern completion menu
set nowrap " Default to no visual line
let &showbreak='↪ '
set number " line numbers
set numberwidth=5 " a little bit of buffer is prettier
set lazyredraw " Smoother display on complex ops (plugins)
" wildmenu does shell-style completion AND tab-through
set wildmode=list:longest,full
" Ignore some extensions when tab-completing
set wildignore=*.swp,*.bak,*.pyc,*.o,*.class
" Only insert up to longest common autocomplete match
set completeopt+=longest
" Basically the default statusline when ruler is enabled, with fugitive
set statusline=%<%f\ %h%m%r%{fugitive#statusline()}%=%-14.(%l,%c%V%)\ %P
" Ensure Airline is always on, instead of only appearing when there's a split.
set laststatus=2
set noshowmode
set ttimeout
set ttimeoutlen=30
set hidden " Allow changing buffers when a file is unwritten
set autoread " If file changed outside vim but not inside, just read it
set switchbuf=useopen " Use existing window if I try to open an already-open buffer
set splitbelow splitright " New h/v split windows show up on bottom/right
set mouse=a " Try to use mouse in console, for scrolling, etc.
set report=0 " Threshold for reporting number of lines changed
" Silence CSApprox's gripes if running a vim without gui support. nvim is fine
if !has('gui') && !has('nvim')
let g:CSApprox_loaded = 1
endif
if has('nvim')
" neovim can automatically switch to skinny cursor in insert mode
let $NVIM_TUI_ENABLE_CURSOR_SHAPE = 1
endif
" TODO: What is the conditional to check for terminal support? Also requires tmux 2.2
if has('termguicolors') && !has('gui_running')
set termguicolors
" Sigh. Needed for tmux where an xterm profile should not be used. Not
" needed by Neovim because it left all the termcap stuff behind. See
" :help xterm-true-color. Fuck terminals.
if $TERM !~ 'xterm' && !has('nvim')
set t_8f=[38;2;%lu;%lu;%lum
set t_8b=[48;2;%lu;%lu;%lum
endif
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
set cursorline
if &diff
colorscheme xoria256 " The best diff highlighting I've found
else
set background=dark
colorscheme base16-default-dark
endif
endif
" Allow global variables, marks, etc. to persist between sessions.
" % saves and restores buffer list when started with no args
if has('viminfo')
set viminfo^=!,%
elseif has('shada') " Neovim
set shada^=!,%
endif
" Indentation {{{2
" Defaults. Overridden appropriately for conventions of many filetypes.
set autoindent " use previous line's indentation
set smarttab " use shiftwidth for indent when at beginning of line
set tabstop=4 " true Tabs display as 8 columns in most tools, but that
" just looks too wide
set shiftwidth=4 " set to the same as tabstop (see #4 in :help tabstop)
set softtabstop=4 " if it looks like a tab, we can delete it like a tab
set expandtab " no tabs! spaces only
set shiftround " < and > will hit indentation levels instead of always -4/+4
set textwidth=0 " do not break lines when line length increases
set cinkeys+=; " figure out C indent when ; is pressed
set showmatch " Show matching brackets.
set matchtime=2
" Use attractive characters to show tabs & trailing spaces
set listchars=tab:»·,trail:·,eol:¬,nbsp:␣
if has('patch-7.3.541')
set formatoptions+=j " Remove comment leader when joining lines
endif
" Folding {{{2
set foldlevelstart=99 " default to all folds open when opening a buffer
set foldnestmax=4 " don't be absurd about how deeply to nest syntax folding
set foldopen-=block " drives me nuts that moving with ] opens folds
" Search {{{2
set grepprg=grep\ -rnH\ --exclude='.*.swp'\ --exclude='*~'\ --exclude=tags
" Enhance :grep
if executable('rg')
set grepprg=rg\ --vimgrep\ $*
set grepformat=%f:%l:%c:%m
elseif executable('ag')
set grepprg=ag\ --vimgrep\ $*
set grepformat=%f:%l:%c:%m
elseif executable('ack')
set grepprg=ack\ --column\ --noheading\ $*
set grepformat=%f:%l:%c:%m
endif
" Autocommands {{{1
" -----------------
if has("autocmd")
augroup BufActions " {{{2
autocmd!
" 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), or for commit messages.
autocmd BufReadPost * call SetCursorPosition()
function! SetCursorPosition()
if &filetype !~ 'commit\c'
if line("'\"") > 0 && line("'\"") <= line("$")
exe 'normal g`"'
normal! zz
endif
end
endfunction "}}}
" Easy helptags regeneration when editing my personal Vim notes
autocmd BufRead ~/.vim/doc/my-notes.txt
\ setlocal modifiable iskeyword=!-~,^*,^\|,^\",192-255 |
\ map <buffer> <Leader>. :w!<CR>:helptags ~/.vim/doc<CR>
" Almost never want to remain in paste mode after insert
autocmd InsertLeave * if &paste | set nopaste paste? | endif
" Try to detect `fc` where `:q!` will surprisingly result in shell execution
autocmd BufRead */bash-fc-* echohl WarningMsg |
\ echo "Use :cquit to abandon fc changes without executing!!" |
\ echohl None
" Skeletons {{{
autocmd BufNewFile build.sbt silent 0read ~/.vim/skeleton/build.sbt| normal ggf"
autocmd BufNewFile Cargo.toml silent 0read ~/.vim/skeleton/Cargo.toml | /^name
autocmd BufNewFile Makefile silent 0read ~/.vim/skeleton/Makefile | /^targets
autocmd BufNewFile .lvimrc silent 0read ~/.vim/skeleton/lvimrc.vim | normal }j
autocmd BufNewFile *.ino silent 0read ~/.vim/skeleton/skeleton.ino | normal 2G
autocmd BufNewFile .projections.json
\ silent 0read ~/.vim/skeleton/projections.json | normal 2G
"}}}
" Auto file perms {{{
autocmd BufNewFile */.netrc,*/.fetchmailrc,*/.my.cnf let b:chmod_new="go-rwx"
autocmd BufNewFile * let b:chmod_exe=1
autocmd BufWritePre * if exists("b:chmod_exe") |
\ unlet b:chmod_exe |
\ if getline(1) =~ '^#!' | let b:chmod_new="+x" | endif |
\ endif
autocmd BufWritePost,FileWritePost * if exists("b:chmod_new")|
\ silent! execute "!chmod ".b:chmod_new." <afile>"|
\ unlet b:chmod_new|
\ endif
"}}}
" Automatically make scripts their own :Make/:Start runner for Dispatch
autocmd BufReadPost *
\ if getline(1) =~# '^#!' |
\ let b:dispatch = getline(1)[2:-1] . ' %' | let b:start = b:dispatch |
\ endif
augroup END "}}}
endif " has("autocmd")
" Mappings {{{1
" -------------
" Because two hands are better than one.
let mapleader = "\<Space>"
let maplocalleader = "\\" " Try comma or Tab? (alas, Ctrl-i interference, damn)
" In and out of command mode quickly, less pain.
noremap <CR> :
" Leader Mappings {{{2
" Lots of great ideas for fewer Shift reaches from:
" http://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity/
nnoremap <Leader>w :w<CR>
nnoremap <Leader>x :xit<CR>
" Navigation with fewer chords
nnoremap <Leader><Space> <C-f>
nnoremap <Leader><BS> <C-b>
nnoremap <Left> {
nnoremap <Right> }
nnoremap <Up> <C-u>
nnoremap <Down> <C-d>
" New trial for NERDtree and Tagbar: <Leader>[ and <Leader>]; or :pop and
" :tag for these? Or <C-i>/<C-o> opening up Tab for LocalLeader...
nnoremap <Leader>[ :NERDTreeToggle<CR>
nnoremap <Leader>] :TagbarToggle<CR>
" Mnemonic: [o]pen files or [f]unctions. <Leader>b is LustyJuggler, change or drop it?
nnoremap <Leader>o :CtrlP<CR>
nnoremap <Leader><C-o> :CtrlPBuffer<CR>
nnoremap <Leader>f :CtrlPBufTag<CR>
nnoremap <Leader><C-f> :CtrlPTag<CR>
nnoremap <Leader>m :CtrlPMRUFiles<CR>
nnoremap <Leader><CR> :CtrlPCmdPalette<CR>
" Copy and paste to/from system clipboard with ease
vnoremap <Leader>y "+y
vnoremap <Leader>d "+d
nnoremap <Leader>p "+p
nnoremap <Leader>P "+P
vnoremap <Leader>p "+p
vnoremap <Leader>P "+P
" Edit vimrc. Use <leader>. mapping (when active buffer) to source it.
nnoremap <leader>ev :split $MYVIMRC<CR>
nnoremap <leader>eV :vsplit $MYVIMRC<CR>
nnoremap <leader>er :split $MYVIMRUNTIME/<CR>
nnoremap <leader>eR :vsplit $MYVIMRUNTIME/<CR>
nnoremap <leader>en :split ~/.vim/doc/my-notes.txt<CR>
nnoremap <leader>eN :vsplit ~/.vim/doc/my-notes.txt<CR>
nnoremap <leader>ef :exec 'split ' . join([$MYVIMRUNTIME, 'after', 'ftplugin', &ft . '.vim'], '/')<CR>
nnoremap <leader>eF :exec 'vsplit ' . join([$MYVIMRUNTIME, 'after', 'ftplugin', &ft . '.vim'], '/')<CR>
" TODO: Should really factor out a function with error handling for the after/ftplugin
nnoremap <leader>sv :source $MYVIMRC<CR>
nnoremap <leader>sf :exec 'source ' . join([$MYVIMRUNTIME, 'after', 'ftplugin', &ft . '.vim'], '/')<Bar>
\ echo 'Sourced ' . &ft . ' customizations.'<CR>
" Search runtime files (plugins) -- warning: slow!
nnoremap <leader>eP :CtrlPRTS<CR>
" TODO: make this a command, something like this but proper completions:
" command -bar -nargs=? -complete=help Help help my-notes-<args>
nnoremap <leader>hh :help my-notes-
" Ready for tab-completion of named Tabular patterns
" Choosing 'gq' since it's similar function to the format command
vnoremap <Leader>gq :Tabularize<space>
vnoremap <Leader>q= :Tabularize assignment<CR>
vnoremap <Leader>q<Bar> :Tabularize bars<CR>
" }}}2
" Tried this in after/ftplugin/help.vim, let's try it globally
nnoremap <BS> <C-t>
" Omni completion shortcut
imap <M-space> <C-x><C-o><C-p>
" Builds, with dispatch.vim
"
" See tpope's wicked Run() function -- I'd like to cook up something
" similar ror ruby, pyflakes/pep8, etc.
"
" TODO: Maybe move to match new Mac media key layout of F7/8/9, but left hand
" is nicer with leader mappings... Shift versions won't work in terminal,
" surprising no one.
nnoremap <F2> :cprev<CR>
nnoremap <F3> :wa<Bar>Dispatch<CR>
nnoremap <F4> :cnext<CR>
nnoremap <Leader><F2> :lprev<CR>
nnoremap <Leader><F3> :wa<Bar>Make<CR>
nnoremap <Leader><F4> :lnext<CR>
nnoremap <LocalLeader><F2> :Copen<CR>
nnoremap <LocalLeader><F3> :Start<CR>
" Clever tpope
nnoremap <silent> <F9> :if &previewwindow<Bar>pclose<Bar>elseif exists(':Gstatus')<Bar>exe 'Gstatus'<Bar>else<Bar>ls<Bar>endif<CR>
" Easy paste mode toggling
" TODO: free this up for something better, with unimpaired's yo I never use it anymore.
set pastetoggle=<F6>
" Toggle search hilighting
" TODO: Practical Vim has the nice idea of overloading <C-l> to do redraw + hlsearch
map <silent> <F11> :set invhlsearch<CR>
imap <silent> <F11> <C-o>:set invhlsearch<CR>
vmap <silent> <F11> :<C-u>set invhlsearch<CR>gv
" It's a fast-moving world these days -- does your scrolling keep up?
noremap <C-y> 2<C-y>
noremap <C-e> 2<C-e>
" Don't use Ex mode, use Q for formatting
vnoremap Q gw
nnoremap Q gwap
" Yank from cursor to end of line, to be consistent with C and D.
nnoremap Y y$
" Select what was just pasted
noremap gV `[v`]
" Why so much hand lifting pain for command editing?
" Allow Emacs/readline-like keys.
cnoremap <C-A> <Home>
cnoremap <C-B> <Left>
cnoremap <C-E> <End>
cnoremap <C-F> <Right>
" Always use the smarter history prefix matching.
cnoremap <C-N> <Down>
cnoremap <C-P> <Up>
cnoremap <C-D> <Del>
if has('mac') && has('gui_running')
cnoremap <M-b> <S-Left>
cnoremap <M-f> <S-Right>
cnoremap <M-BS> <C-W>
else
cnoremap <ESC>b <S-Left>
cnoremap <ESC><C-B> <S-Left>
cnoremap <ESC>f <S-Right>
cnoremap <ESC><C-F> <S-Right>
cnoremap <ESC><BS> <C-W>
cnoremap <ESC><C-H> <C-W>
endif
" The defaults for these can be useful, keep them available. See also rsi.vim
cnoremap <C-X><C-A> <C-A>
cnoremap <C-X><C-D> <C-D>
" Default is Ctrl-F but we've just remapped it
set cedit=<C-y>
" Easy window split navigation
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
map <C-h> <C-w>h
" Symmetry with tmux previous window binding
map <C-w>; <C-w>p
" Resizing, assuming left Option as Esc here
map <Esc>= <C-w>3+
map <Esc>- <C-w>3-
map <Esc>, <C-w>3<
map <Esc>. <C-w>3>
" Keep a block highlighted while shifting
vnoremap < <gv
vnoremap > >gv
" Line "bubbling" with the help of unimpaired.vim
nmap <C-UP> [e
nmap <C-DOWN> ]e
vmap <C-UP> [egv
vmap <C-DOWN> ]egv
" Toggle a window's height stickiness, so C-w = doesn't equalize it
nmap <leader>` :set invwinfixheight winfixheight?<CR>
" QuickLook the current file. With Brett Terpstra's awesome CSS fork of
" the MMD QuickLook plugin, this sure beats browser-based Markdown preview.
if has('mac')
" Warning: OS X since Lion or so has fucked up qlmanage :-/
nnoremap <Leader>ql :write<CR>:sil !qlmanage -p % >& /dev/null &<CR>:redraw!<CR>
" dash.vim
nmap <silent> <Leader>k <Plug>DashSearch
endif
" Terminal Function key hackery {{{
"
" Gross, but I'm tired of trying to get various terminal emulators to emit
" consistent fucking escape sequences. These, for now, are whatever iTerm2 in
" xterm-256color mode emits for function keys...
"
" http://stackoverflow.com/questions/3519532/mapping-function-keys-in-vim
" http://stackoverflow.com/questions/9950944/binding-special-keys-as-vim-shortcuts
"
" NOTE: Neovim ends a lot of the pain.
if has('mac') && (index(['alacritty', 'xterm-256color', 'screen-256color'], $TERM) >= 0)
map <Esc>OP <F1>
map <Esc>OQ <F2>
map <Esc>OR <F3>
map <Esc>OS <F4>
map <Esc>[16~ <F5>
map <Esc>[17~ <F6>
map <Esc>[18~ <F7>
map <Esc>[19~ <F8>
map <Esc>[20~ <F9>
map <Esc>[21~ <F10>
map <Esc>[23~ <F11>
map <Esc>[24~ <F12>
imap <Esc>[17~ <F6>
imap <Esc>[23~ <F11>
endif
"}}}
" Ellipsis. Mac Opt-; doesn't work in console.
if has('digraphs')
digraph ./ 8230
endif
" Lotsa TextMate-inspired Mappings
runtime include/textmate-mappings.vim
" Language- and plugin-specific Preferences {{{1
" ----------------------------------------------
" For (sort of) modern standards in :TOhtml output
let g:html_use_css = 1
let g:html_use_xhtml = 0
if has("autocmd")
augroup FiletypeSets "{{{
autocmd!
autocmd BufNewFile,BufRead jquery.*.js set ft=javascript syntax=jquery
autocmd BufNewFile,BufRead *.j2 set ft=jinja
autocmd BufNewFile,BufRead *.mako set ft=mako
" Remove for https://github.com/dag/vim-cabal -- it's WIP for
" modularization of https://github.com/dag/vim2hs
autocmd BufRead,BufNewFile *.cabal,*/.cabal/config,cabal{.sandbox,}.config setfiletype cabal
autocmd BufRead cabal.sandbox.config setlocal readonly
augroup END "}}}
augroup OmniCompletion "{{{
autocmd!
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
" Hide completion doc hints automatically after no longer needed.
" CompleteDone event also possible but InsertLeave is less herky jerky.
autocmd InsertLeave *.py,*.scala silent! pclose
augroup END "}}}
" TODO: might soon want to start organizing this ballooning group of stuff
" in after/ftplugin files :-)
augroup FToptions "{{{
autocmd!
" Default text files to 78 characters.
autocmd FileType text setlocal textwidth=78
autocmd FileType html,xhtml,xml,htmldjango,htmljinja,eruby,mako,cucumber setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
autocmd FileType coffee,ruby,vim,yaml setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
autocmd FileType javascript setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
" Rails.vim defaults to 2 for traditional JS, I prefer 4
autocmd User Rails.javascript* setlocal expandtab shiftwidth=4 tabstop=4 softtabstop=4
autocmd User Rails.javascript.coffee* setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2
" Comment continuation, joining
autocmd FileType sh setlocal formatoptions+=roj
" Auto-wrap comments to a nicely-readable width, assuming formatoptions+=c
autocmd FileType go setlocal textwidth=80
" Enhancements for whitespace-significant langs. Folding still a bit slow.
autocmd FileType coffee,python BracelessEnable +indent +fold
" Use Leader-. to write and execute. Prefer :Dispatch if shebanged though.
autocmd FileType vim map <buffer> <Leader>. :w!<CR>:source %<CR>
autocmd FileType sh map <buffer> <Leader>. :w!<CR>:!/bin/sh %<CR>
autocmd FileType ruby map <buffer> <Leader>. :w!<CR>:!ruby %<CR>
autocmd FileType python map <buffer> <Leader>. :w!<CR>:!python %<CR>
" Be trusting about Ruby code being evaluated for autocompletion...
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
" Easily lookup documentation
" TODO: Perhaps make <Leader>k a convention for all language docs
if has('mac')
" The first keywords are custom search profiles that I've set up -- they
" search the subsequent docsets as a group, ranked in the order shown here.
autocmd User Rails :DashKeywords rr rails ruby
autocmd User Rails.javascript* :DashKeywords jj js jquery
autocmd User Rails.javascript.coffee* :DashKeywords cjj coffee js jquery
autocmd FileType scala :DashKeywords scala akka play scaladoc
else
autocmd FileType ruby noremap <buffer> <leader>rb :OpenURL http://apidock.com/ruby/<cword><CR>
autocmd FileType ruby noremap <buffer> <leader>rr :OpenURL http://apidock.com/rails/<cword><CR>
endif
" Use fancier man.vim version instead of keywordprg
autocmd FileType c,sh nnoremap K :Man <cword><CR>
autocmd FileType vim setlocal keywordprg=:help
autocmd FileType javascript let javascript_enable_domhtmlcss=1
autocmd FileType xml let xml_use_xhtml = 1 " default xml to self-closing tags
autocmd FileType vimwiki setlocal foldlevel=2 textwidth=78 linebreak
autocmd FileType vimwiki map <buffer> <M-Space> <Plug>VimwikiToggleListItem
autocmd FileType vimwiki map <buffer> <Leader>wg :VimwikiGoto<space>
autocmd FileType vimwiki map <buffer> <Leader>w/ :VimwikiSearch<space>/
autocmd FileType text,gitcommit,vimwiki setlocal spell
autocmd FileType godoc,qf nnoremap <silent><buffer> q :q<CR>
autocmd FileType man setlocal nocursorline nomodifiable
" Quickly get back to the last header or source.
autocmd BufLeave *.{c,cpp,erl,ml} mark C
autocmd BufLeave *.{h,hrl,mli} mark H
augroup END "}}}
" Fun with some goodies hidden in vim-git ftplugins. {{{
augroup GitTricks
autocmd!
autocmd FileType gitrebase
\ nnoremap <buffer> P :Pick<CR> |
\ nnoremap <buffer> S :Squash<CR> |
\ nnoremap <buffer> E :Edit<CR> |
\ nnoremap <buffer> R :Reword<CR> |
\ nnoremap <buffer> F :Fixup<CR> |
\ nnoremap <buffer> C :Cycle<CR>
augroup END " }}}
augroup Compilers "{{{
" With regards to tpope. See his vimrc for more ideas.
autocmd!
" TODO: Focused tests a la :.Rake, try to use spin, etc. when available
autocmd FileType cucumber let b:dispatch = 'cucumber %'
autocmd FileType ruby
\ let b:start = executable('pry') ? 'pry -r "%:p"' : 'irb -r "%:p"' |
\ if expand('%') =~# '_test\.rb$' |
\ let b:dispatch = 'testrb %' |
\ elseif expand('%') =~# '_spec\.rb$' |
\ let b:dispatch = 'rspec %' |
\ else |
\ let b:dispatch = 'ruby -wc %' |
\ endif
autocmd User Bundler
\ if &makeprg !~# 'bundle' | setl makeprg^=bundle\ exec\ | endif
autocmd FileType vim
\ if exists(':Runtime') |
\ let b:dispatch = ':Runtime' |
\ let b:start = ':Runtime|PP' |
\ else |
\ let b:dispatch = ":unlet! g:loaded_{expand('%:t:r')}|source %" |
\ endif
augroup END "}}}
augroup BaselineCompletion " {{{
autocmd!
autocmd FileType * if exists("+omnifunc") && &omnifunc == "" | setlocal omnifunc=syntaxcomplete#Complete | endif
autocmd FileType * if exists("+completefunc") && &completefunc == "" | setlocal completefunc=syntaxcomplete#Complete | endif
augroup END " }}}
augroup Cursorline "{{{
autocmd!
" Turn on cursorline only on active window. Reduces clutter, easier to
" find your place.
"
" cursorline is slow:
" http://briancarper.net/blog/590/cursorcolumn--cursorline-slowdown
" https://gist.github.com/pera/2624765
" https://code.google.com/p/vim/issues/detail?id=282
autocmd WinEnter,BufRead * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
autocmd InsertEnter * setlocal nocursorline
autocmd InsertLeave * setlocal cursorline
augroup END "}}}
" Goyo: distraction-free writing {{{
" This was VimRoom's default mapping:
nnoremap <Leader>V :Goyo<CR>
function! s:GoyoEnter()
let s:goyo_scrolloff_save = &scrolloff
set scrolloff=999
set guioptions-=r
if !empty($TMUX) && !has('gui_running')
silent !tmux set status off
endif
endfunction
function! s:GoyoLeave()
let &scrolloff = s:goyo_scrolloff_save
set guioptions+=r
if !empty($TMUX) && !has('gui_running')
silent !tmux set status on
endif
endfunction
autocmd! User GoyoEnter
autocmd! User GoyoLeave
autocmd User GoyoEnter nested call <SID>GoyoEnter()
autocmd User GoyoLeave nested call <SID>GoyoLeave()
" }}}
" Built-in cruft I never use -- don't bother loading it {{{
let g:loaded_getscriptPlugin = 1
let g:loaded_gzip = 1
let g:loaded_logipat = 1
let g:loaded_tarPlugin = 1
let g:loaded_tar = 1
let g:loaded_vimballPlugin = 1
let g:loaded_vimball = 1
let g:loaded_zipPlugin = 1
let g:loaded_zip = 1
" }}}
" Haskell
"
" gf to buffer-local filetype settings at:
" ~/.vim/after/ftplugin/haskell.vim
let g:necoghc_enable_detailed_browse = 1
" Vimerl for Erlang
"
" Overwriting any existing buffer content is too surprising.
let erlang_skel_replace = 0
let erlang_skel_header = { "author": "Ches Martin" }
" Python -- see also ~/.vim/after/ftplugin/python.vim {{{
let python_highlight_all = 1
" The way jedi-vim handles mappings with variable assignments is annoying --
" like so many plugins, it ought to have a <Plug> map approach... I'm
" leaving the (intrusive) default mappings for now, because it's a pain to
" manually do all the other stuff that auto_initialization does if I turn it
" off. The plugin at least needs an option to only skip its mappings.
" let g:jedi#auto_initialization = 0
let g:jedi#auto_close_doc = 0 " Overly jerky, spastic UI layout shifts
let g:jedi#completions_enabled = 0 " We get jedi already with YouCompleteMe
" vim-ipython - it's crusty but still fairly useful. Give it some love.
let g:ipy_completefunc = 'none' " Don't bother with completion, we have YCM/jedi
let g:ipy_perform_mappings = 0 " Lots of intrusive mappings I'm not fond of
" }}}
" Go (golang) {{{
" Tell vim-go to use goimports instead of gofmt on save
let g:go_fmt_command = 'goimports'
" Make things prettier -- unfortunately this is slow as balls
" let g:go_highlight_functions = 1
" let g:go_highlight_methods = 1
" let g:go_highlight_structs = 1
" let g:go_highlight_operators = 1
" }}}
" Rust {{{
" For Racer to go to definition, autocomplete
let $RUST_SRC_PATH = expand('~/src/rust/rust/src/')
" }}}
" Tagbar {{{
runtime include/tagbar-types.vim
let g:tagbar_autoclose = 1
" }}}
" NERDTree
let NERDTreeWinPos = 'right'
let NERDTreeShowBookmarks = 1
let NERDTreeQuitOnOpen = 1 " hide after opening a file
let NERDTreeHijackNetrw = 0 " I like netrw when I `:e somedir`
let NERDTreeIgnore = ['\.git', '\.hg', '\.svn', '\.DS_Store', '\.pyc']
" NERDCommenter
let NERDSpaceDelims = 1 " use a space after comment chars
let NERDDefaultAlign = 'left'
" Not cool when end-of-line comments break when uncommenting /* */ blocks:
let NERDRemoveAltComs = 0
" QFEnter - open quickfix items where you want them {{{
" Change mappings to mimic CtrlP
" TODO: ought to contribute <Plug> mapping support to this plugin
" https://github.com/romainl/vim-qf is cool, the ack.vim mappings also
" aren't <Plug> mappings -- contribute that
let g:qfenter_keymap = {}
let g:qfenter_keymap.vopen = ['<C-v>']
let g:qfenter_keymap.hopen = ['<C-CR>', '<C-s>', '<C-x>']
let g:qfenter_keymap.topen = ['<C-t>']
" ack.vim-like, unfortunately no way to open in tab in background I don't think
let g:qfenter_keymap.open_keep = ['go']
let g:qfenter_keymap.hopen_keep = ['H']
let g:qfenter_keymap.topen_keep = ['T']
let g:qfenter_keymap.vopen_keep = ['gv']
" Autopreview
let g:qfenter_keymap.cnext_keep = ['<C-n>']
let g:qfenter_keymap.cprev_keep = ['<C-p>']
" Don't open the quickfix window in each newly-opened tab
let g:qfenter_enable_autoquickfix = 0
" Preview support, I think this was my own WIP implementation
let g:qfenter_popen_map = ['p']
" let g:qfenter_pcnext_map = ['<C-n>']
" let g:qfenter_pcprev_map = ['<C-p>']
" }}}
" Syntastic - Syntax and Lint/Style Checking {{{
nnoremap <F5> :SyntasticCheck<CR> :Errors<CR>
nnoremap <Leader><F5> :SyntasticToggleMode<CR>
let g:syntastic_aggregate_errors = 1
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_error_symbol = '✗' " ✖, ✘, ☝, ✋
let g:syntastic_warning_symbol = '⚠'
let g:syntastic_style_error_symbol = '❗' " 🌶, 💦, 🖉, 🙈
let g:syntastic_style_warning_symbol = '❕'
" TODO: SBT ignored or passive?
let g:syntastic_ignore_files = ['\m\c\.h$', '\m\.sbt$']
" Tuning for stuff that is slow or obnoxious
let g:syntastic_mode_map = {
\ 'mode': 'active',
\ 'passive_filetypes': ['scala', 'sbt', 'java'] }
let g:syntastic_direnv_checkers = ['sh', 'shellcheck', 'shfmt']
let g:syntastic_go_checkers = ['go', 'golint', 'govet']
let g:syntastic_help_checkers = ['proselint']
let g:syntastic_markdown_checkers = ['proselint']
" Scala has fsc and scalac checkers--running both is pretty redundant and
" slow. An explicit `:SyntasticCheck scalac` can always run the other.
let g:syntastic_scala_checkers = ['fsc']
let g:syntastic_text_checkers = ['proselint']
" }}}
" TagmaTasks {{{
let g:TagmaTasksHeight = 8
let g:TagmaTasksTokens = ['FIXME', 'TODO', 'NOTE', 'XXX', 'OPTIMIZE', 'PONY']
let g:TagmaTasksJumpTask = 0
" The plugin's jump mappings conflict with Unimpaired's tag nav
let g:TagmaTasksJumpKeys = 0
" Plugin is buggy, supposed to set this to empty but does so too late.
let g:TagmaTasksRegexp = ''
" Everything that seems more natural conflicts: <Leader>t with test runs;
" <LocalLeader>t with type checks in typed langs; <C-t> with tag navigation.
if has('mac') && has('gui_running')
let g:TagmaTasksPrefix = '<M-t>'
else
let g:TagmaTasksPrefix = '<Esc>t'
endif " }}}
" Open the YankRing window
if has('mac') && has('gui_running')
nnoremap <silent> <M-v> :YRShow<CR>
else
" Console with Option as Escape
nnoremap <silent> <Esc>v :YRShow<CR>
endif
let g:yankring_history_dir = s:my_backups_rootdir
let g:yankring_window_height = 12
" Make sure YankRing plays nice with custom remapping.
" See `:h yankring-custom-maps`
function! YRRunAfterMaps()
nnoremap <silent> Y :<C-U>YRYankCount 'y$'<CR>
endfunction
let g:dbext_default_history_file = s:my_backups_rootdir . '/dbext_sql_history.txt'
" Lusty Juggler buffer switcher
let g:LustyJugglerShowKeys = 'a'
let g:LustyJugglerSuppressRubyWarning = 1
let g:LustyJugglerDefaultMappings = 0
nmap <silent> <leader>b :LustyJuggler<CR>
" Juggler is packaged with LustyExplorer, which I'm not interested in
let g:loaded_lustyexplorer = 1
" Gist {{{
let g:gist_put_url_to_clipboard_after_post = 1
let g:gist_show_privates = 1
let g:gist_post_private = 1
" detect filetype if vim failed autodetection
let g:gist_detect_filetype = 1
" :w! updates a Gist, not plain :w
let g:gist_update_on_write = 2
if has('mac')
let g:gist_clip_command = 'pbcopy'
endif "}}}
" Tslime {{{
" Tslime provides a simple means of sending text to a tmux pane, most
" usefully a REPL.
"
" There are some alternatives like Vimux, but I like the way Tslime prompts
" for the window/pane to use, and allows reconfiguring it. This better suits
" a larger pane for a REPL, where Vimux optimizes for running tests/builds
" in a small pane that it creates. I prefer Dispatch for that. The new
" vim-tmux-runner is worth a look.
"
" The Turbux test runner plugin can use Tslime, but its auto-detection of
" backends gives precendence to Dispatch. This is normally desirable since
" Dispatch can parse error output from async test/build runs into quickfix,
" but if Tslime is preferable in some scenario, set:
"
" let g:turbux_runner = 'tslime'
"
" A reminder for overriding Turbux's default test runner auto-selection:
"
" let g:turbux_command_rspec = 'spin push'
"
vmap <C-c><C-c> <Plug>SendSelectionToTmux
nmap <C-c><C-c> <Plug>NormalModeSendToTmux
nmap <C-c>r <Plug>SetTmuxVars
" }}}
" Opt-in for fenced code block highlighting
let g:markdown_fenced_languages = [
\ 'coffee',
\ 'js=javascript',
\ 'python',
\ 'ruby', 'erb=eruby',
\ 'scala',
\ 'vim'
\ ]
" Vimwiki {{{
" Using <Space>w to write files now, need to keep the old home for this.
let g:vimwiki_map_prefix = ',w'
" My custom functions below define a web link handler
let g:vimwiki_menu = 'Plugin.Vimwiki'
let g:vimwiki_use_mouse = 1 " A rare case where I may actually use the mouse :-)
let g:vimwiki_folding = 1
let main_wiki = {}
let main_wiki.path = '~/src/vimwiki'
let main_wiki.path_html = '~/src/vimwiki/html'
let main_wiki.nested_syntaxes =
\ {'python': 'python', 'ruby': 'ruby', 'sh': 'sh', 'vimscript': 'vim'}
" 'diary' makes me feel like a teenage girl
let main_wiki.diary_rel_path = 'journal/'
let main_wiki.diary_index = 'journal'
let main_wiki.diary_header = 'Journal'
let g:vimwiki_list = [main_wiki]
" }}}
if has('mac')
" Map vim filetypes to Dash search keywords
let g:dash_map = {
\ 'python' : 'py',
\ 'javascript' : 'js'
\ }
" netrw won't delete non-empty directories by default, which is annoying
" TODO: Safe Linux equivalent to trash since this can be easy to fat-finger
if executable('trash')
let g:netrw_localrmdir = 'trash' " brew install trash
endif
endif
" Merlin - Semantic completion for OCaml {{{
"
" Installed along with its server runtime through OPAM, so the Vim plugin is
" loaded by giving NeoBundle a local path -- see:
"
" https://github.com/the-lambda-church/merlin/wiki/vim-from-scratch
"
if neobundle#is_installed('merlin')
let g:syntastic_ocaml_checkers = ['merlin']
" Semantic text objects based on AST
let g:merlin_textobject_grow = 'm'
let g:merlin_textobject_shrink = 'M'
" See the above TODO for java patterns
" let g:neocomplete#force_omni_input_patterns.ocaml = '[^. *\t]\.\w*\|\h\w*|#'
endif " }}}
endif " has("autocmd")
" Plugin Mappings {{{2
" Note: I prefer to keep ftplugin-specific mappings in ~/.vim/after/ftplugin
" as a matter of organization. Jump here with gf and use unimpaired's ]f & [f:
"
" ~/.vim/after/ftplugin/haskell.vim
"
" Ack Search {{{
" TODO: something to quickly search cword, e.g.
" https://robots.thoughtbot.com/faster-grepping-in-vim
map <Leader>a :Ack! ''<Left>
map <Leader>A :AckWindow! ''<Left>
map <Leader>l :LAck! '' %<Left><Left><Left>
map <Leader>n :AckFromSearch!<CR>
" Mnemonic: helpgrep, but consider making this a prefix for Lawrencium...