-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
636 lines (509 loc) · 16.8 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
set nocompatible
filetype off
" map leader to ,
let mapleader = ","
let maplocalleader="\\"
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
set autowriteall
" Get correct $PATH from .bashrc
set shell=bash
" Disable .swp file creation
set noswapfile
Plugin 'tpope/vim-repeat'
" RTF copying for Keynote copy + paste
Plugin 'vagmi/rtf-highlight'
" Jade templating
Plugin 'vim-scripts/jade.vim'
" Javascript
Plugin 'pangloss/vim-javascript'
Plugin 'kchmck/vim-coffee-script'
Plugin 'mxw/vim-jsx'
Plugin 'tpope/vim-jdaddy'
"Plugin 'isRuslan/vim-es6'
Plugin 'leafgarland/typescript-vim'
"Plugin 'ruanyl/vim-fixmyjs'
let g:fixmyjs_engine = 'eslint'
let g:fixmyjs_rc_filename = ['.eslintrc.js']
augroup js
autocmd!
autocmd BufRead *.js,*.es6,*.jsx nmap <silent> <buffer> <leader>ja vi{gL:
autocmd BufRead *.js,*.es6,*.jsx noremap <silent> <buffer> <leader>fj :Fixmyjs<cr>
autocmd Filetype javascript nnoremap <leader>rf :call RunYarnTest()<cr>
augroup end
function! RunYarnTest()
VimuxRunCommand("yarn test " . expand("%"))
endfunction
" Markdown
Plugin 'plasticboy/vim-markdown'
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_conceal = 0
augroup mkd
autocmd!
autocmd BufRead *\.markdown,*\.md,*\.txt set ai formatoptions=tcroqn2 comments=n:>
autocmd BufRead *\.markdown,*\.md,*\.txt setlocal conceallevel=0
autocmd BufRead *\.markdown,*\.md,*\.txt setlocal formatoptions=l
autocmd BufRead *\.markdown,*\.md,*\.txt setlocal lbr
autocmd BufRead *\.markdown,*\.md,*\.txt map j gj
autocmd BufRead *\.markdown,*\.md,*\.txt map k gk
autocmd BufRead *\.markdown,*\.md,*\.txt setlocal smartindent
autocmd BufRead *\.markdown,*\.md,*\.txt setlocal nolist
autocmd BufRead *\.markdown,*\.md,*\.txt nnoremap <buffer> <leader>sp :setlocal spell! spelllang=en_gb<cr>
autocmd BufRead *\.markdown,*\.md,*\.txt nnoremap <buffer> <leader>ft :TableFormat<cr>
autocmd BufRead *\.markdown,*\.md,*\.txt iabbrev <buffer> cblock {% raw FOO %}<cr>{% highlight %}<cr>{% endraw %}<cr>{% endhighlight %}<esc>?FOO<cr>cw
autocmd BufEnter *\.markdown,*\.md,*\.txt call AutoGoyoEnable()
autocmd BufEnter *\.markdown,*\.md,*\.txt call pencil#init()
autocmd BufEnter *\.markdown,*\.md,*\.txt nnoremap <leader>t :call GoyoToggleAndFind()<cr>
augroup END
function! GoyoToggleAndFind()
if $AUTO_GOYO_MARKDOWN
:Goyo
endif
:FZF
endfunction
function! AutoGoyoEnable()
if $AUTO_GOYO_MARKDOWN
Goyo 100
endif
endfunction
" prose
Plugin 'junegunn/goyo.vim'
Plugin 'reedes/vim-pencil'
let g:pencil#wrapModeDefault = 'soft'
map gp :Goyo <bar> :TogglePencil<cr> <bar> :set conceallevel=0<CR>
" Better SQL syntax highlighting
Plugin 'shmup/vim-sql-syntax'
" Python
"
" vimux for pytest, adapted from https://github.com/pitluga/vimux-nose-test/blob/master/plugin/vimux-nose-test.vim
"
command! RunPytestTestBuffer :call RunPytestTestBuffer()
command! RunPytestTestFocused :call RunPytestTestFocused()
function! RunPytestTestBuffer()
call _run_pytesttests(expand("%"))
endfunction
function! RunPytestTestFocused()
let test_name = _pytest_test_search("def test_")
if test_name == ""
echoerr "Couldn't find class and test name to run focused test."
return
endif
call _run_pytesttests(expand("%") . "::" . test_name)
endfunction
function! _pytest_test_search(fragment)
let line_num = search(a:fragment, "bs")
if line_num > 0
''
return split(split(getline(line_num), " ")[1], "(")[0]
else
return ""
endif
endfunction
function! _run_pytesttests(test)
call VimuxRunCommand("python -m pytest -s " . a:test)
endfunction
augroup python
autocmd!
autocmd Filetype python nnoremap <leader>rl :RunPytestTestFocused<cr>
autocmd Filetype python nnoremap <leader>rf :RunPytestTestBuffer<cr>
autocmd BufNewFile,BufRead *.py set tabstop=4
autocmd BufNewFile,BufRead *.py set softtabstop=4
autocmd BufNewFile,BufRead *.py set shiftwidth=4
autocmd BufNewFile,BufRead *.py set expandtab
autocmd BufNewFile,BufRead *.py set autoindent
autocmd BufNewFile,BufRead *.py set fileformat=unix
autocmd BufNewFile,BufRead *.py iabbrev pydb import ipdb; ipdb.set_trace()
autocmd BufNewFile,BufRead *.py let b:ale_fixers = []
augroup END
Plugin 'vim-scripts/indentpython.vim'
Plugin 'raimon49/requirements.txt.vim'
" Use the old vim regex engine (version 1, as opposed to version 2, which was
" introduced in Vim 7.3.969). The Ruby syntax highlighting is significantly
" slower with the new regex engine.
set re=1
" Ruby and Rails
Plugin 'vim-ruby/vim-ruby'
Plugin 'mtscout6/vim-cjsx'
Plugin 'tpope/vim-rails'
Plugin 'tmhedberg/matchit'
Plugin 'kana/vim-textobj-user'
Plugin 'nelstrom/vim-textobj-rubyblock'
Plugin 'danchoi/ruby_bashrockets.vim'
" Rust
Plugin 'rust-lang/rust.vim'
let g:rustfmt_autosave = 1
" LSP / Linting
Plugin 'dense-analysis/ale'
let g:ale_linters = {
\ 'javascript': ['eslint', 'prettier'],
\ 'rust': ['cargo'],
\}
let g:ale_fixers = {
\ 'javascript': ['prettier'],
\}
" only lint on save
let g:ale_lint_on_text_changed = 'never'
let g:ale_linters_explicit = 1
let g:ale_fix_on_save = 1
" force json files to use json linting instead of javascript
augroup json
autocmd!
au BufRead,BufNewFile *.json set filetype=json
augroup END
" SCSS
augroup scss
autocmd!
au BufRead,BufNewFile *.scss set filetype=scss
augroup END
augroup haml
autocmd!
" treat hamlbars and hamlc the same as haml
au BufRead,BufNewFile *.hamlc set ft=haml
au BufRead,BufNewFile *.hamlbars set ft=haml
augroup END
" Clojure
Plugin 'tpope/vim-classpath'
Plugin 'tpope/vim-fireplace.git'
Plugin 'tpope/vim-dispatch'
Plugin 'guns/vim-clojure-static.git'
" always only indent every subform with 2 spaces for these forms
let g:clojure_special_indent_words = 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn,fact,facts'
Plugin 'kien/rainbow_parentheses.vim'
Plugin 'guns/vim-sexp'
Plugin 'tpope/vim-sexp-mappings-for-regular-people'
Plugin 'guns/vim-slamhound'
Plugin 'dgrnbrg/vim-redl'
let g:rbpt_colorpairs = [
\ ['blue', '#FF6000'],
\ ['cyan', '#00FFFF'],
\ ['darkgreen', '#00FF00'],
\ ['LightYellow', '#c0c0c0'],
\ ['blue', '#FF6000'],
\ ['cyan', '#00FFFF'],
\ ['darkgreen', '#00FF00'],
\ ['LightYellow', '#c0c0c0'],
\ ['blue', '#FF6000'],
\ ['cyan', '#00FFFF'],
\ ['darkgreen', '#00FF00'],
\ ['LightYellow', '#c0c0c0'],
\ ['blue', '#FF6000'],
\ ['cyan', '#00FFFF'],
\ ['darkgreen', '#00FF00'],
\ ['LightYellow', '#c0c0c0'],
\ ]
let g:rbpt_max = 16
function! IsFireplaceConnected()
try
return has_key(fireplace#platform(), 'connection')
catch /Fireplace: :Connect to a REPL or install classpath.vim/
return 0 " false
endtry
endfunction
function! NreplStatusLine()
if IsFireplaceConnected()
return 'nREPL Connected'
else
return 'No nREPL Connection'
endif
endfunction
function! VimuxSlime()
call VimuxRunCommand(@v, 0)
endfunction
augroup clojure
autocmd!
" If text is selected, save it in the v buffer and send that buffer it to tmux
autocmd BufEnter *.cljs,*.clj,*.cljs.hl vmap <Leader>sl "vy :call VimuxSlime()<CR>
" Select current paragraph and send it to tmux
autocmd BufEnter *.cljs,*.clj,*.cljs.hl nmap <Leader>sl vip<Leader>sl<CR>
autocmd BufEnter *.cljs,*.clj,*.cljs.hl RainbowParenthesesActivate
autocmd BufEnter *.cljs,*.clj,*.cljs.hl RainbowParenthesesLoadRound
autocmd BufEnter *.cljs,*.clj,*.cljs.hl RainbowParenthesesLoadSquare
autocmd BufEnter *.cljs,*.clj,*.cljs.hl RainbowParenthesesLoadBraces
" autocmd BufEnter *.cljs,*.clj,*.cljs.hl setlocal iskeyword+=?,-,*,!,+,/,=,<,>,.,:
" autocmd Filetype clojure call SetBasicStatusLine()
" autocmd Filetype clojure set statusline+=\ [%{NreplStatusLine()}] " REPL connection status
autocmd Filetype clojure nmap <buffer> gf <Plug>FireplaceDjump
autocmd Filetype clojure nnoremap <buffer> <leader>sh :Slamhound<cr>
autocmd Filetype clojure nnoremap <silent> <buffer> <leader>rf :Require<cr>:RunTests<cr>
autocmd Filetype clojure nnoremap <silent> <buffer> <leader>rl :Require<cr>:.RunTests<cr>
autocmd Filetype clojure nnoremap <silent> <buffer> <leader>eo :Eval<cr>
autocmd Filetype clojure nnoremap <silent> <buffer> <leader>e! :Eval!<cr>
autocmd Filetype clojure imap <buffer> <Up> <Plug>clj_repl_uphist.
autocmd Filetype clojure imap <buffer> <Down> <Plug>clj_repl_downhist.
" autocmd BufLeave *.cljs,*.clj,*.cljs.hl call SetBasicStatusLine()
augroup END
" Profiling Rabbithole Macro
nnoremap <leader>pf Oconst start=Date.now();<esc>joconsole.log(`--- abc : ${Date.now() - start}ms`);<esc>:s/abc/\=expand('%:p').':'.line('.')/<cr>
" Vimux
Plugin 'benmills/vimux'
Plugin 'thegreatape/vimux-ruby-test'
let g:vimux_ruby_file_relative_paths = 1
augroup ruby
autocmd!
" test running shortcuts
autocmd Filetype ruby nnoremap <leader>rl :RunRubyFocusedTest<cr>
autocmd Filetype ruby nnoremap <leader>rf :RunAllRubyTests<cr>
autocmd Filetype ruby nnoremap <leader>rc :VimuxClosePanes<cr>
" for active admin arb templates
autocmd BufRead,BufNewFile *.arb setfiletype ruby
" Guardfiles and axlsx are just ruby
autocmd BufRead,BufNewFile *.axlsx set filetype=ruby
autocmd BufRead,BufNewFile Guardfile set filetype=ruby
augroup end
let g:VimuxOrientation = "h"
let g:VimuxHeight = "30"
let g:VimuxUseNearestPane = 1
let g:vimux_ruby_clear_console_on_run = 0
" Navigating tmux/vim splits seamlessly
Plugin 'thegreatape/vim-tmux-navigator'
" Elixir
Plugin 'elixir-lang/vim-elixir'
Plugin 'slashmili/alchemist.vim'
" Go
Plugin 'fatih/vim-go'
augroup go
autocmd!
autocmd Filetype go inoremap <C-n> <C-x><C-o>
augroup END
" Less
Plugin 'groenewege/vim-less'
" Elm
Plugin 'lambdatoast/elm.vim'
" Terraform
Plugin 'hashivim/vim-terraform'
" Ansible-specific YAML
Plugin 'chase/vim-ansible-yaml'
" fix backspace flicker caused by elm plugin mapping
" it to dedenting in insert mode
let g:Haskell_no_mapping = 1
" Ctags
Plugin 'ludovicchabant/vim-gutentags'
Plugin 'vim-scripts/taglist.vim'
" Using FZF to search project tags, taken from
" https://github.com/junegunn/fzf/wiki/Examples-%28vim%29#jump-to-tags
" removed tag-generating call in s:tags(), since we want
" to use the gutentags launched version
function! s:tags_sink(line)
let parts = split(a:line, '\t\zs')
let excmd = matchstr(parts[2:], '^.*\ze;"\t')
execute 'silent e' parts[1][:-2]
let [magic, &magic] = [&magic, 0]
execute excmd
let &magic = magic
endfunction
function! s:tags()
call fzf#run({
\ 'source': 'cat '.join(map(tagfiles(), 'fnamemodify(v:val, ":S")')).
\ '| grep -v -a ^!',
\ 'options': '+m -d "\t" --with-nth 1,4.. -n 1 --tiebreak=index',
\ 'down': '40%',
\ 'sink': function('s:tags_sink')})
endfunction
command! Tags call s:tags()
" gt to go to tag under cursor
nnoremap gt <C-]>
" <leader>gt to open fuzzy tag finder
nnoremap <leader>gt :Tags<cr>
" Utility plugins
Plugin 'scrooloose/nerdcommenter'
Plugin 'vim-scripts/bufkill.vim'
Plugin 'godlygeek/csapprox'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-fugitive'
Plugin 'tpope/vim-rhubarb'
Plugin 'godlygeek/tabular.git'
Plugin 'kien/ctrlp.vim.git'
Plugin 'junegunn/fzf'
Plugin 'tpope/vim-abolish'
Plugin 'tommcdo/vim-lion'
Plugin 'malkomalko/projections.vim'
Plugin 'terryma/vim-multiple-cursors'
Plugin 'wincent/ferret'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
let g:airline_theme='zenburn'
let g:airline#extensions#ale#enabled = 1
function! AirlineInit()
let g:airline_section_a=''
let g:airline_section_b=airline#section#create(['%<', 'file', g:airline_symbols.space, 'readonly'])
let g:airline_section_c=''
let g:airline_section_y="%{airline#util#wrap(airline#extensions#branch#get_head(),0)}"
let g:airline_section_z="%{gutentags#statusline()}"
endfunction
augroup airfline
autocmd!
autocmd User AirlineToggledOn call AirlineInit()
augroup end
Plugin 'terryma/vim-expand-region'
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
" nix
Plugin 'LnL7/vim-nix'
" kotlin
Plugin 'udalov/kotlin-vim'
" swift
Plugin 'keith/swift.vim'
" applescript
Plugin 'dearrrfish/vim-applescript'
" searching
Plugin 'rking/ag.vim'
"nnoremap <leader>ag :
nnoremap <leader>ag :set operatorfunc=AgOperator<cr>g@
vnoremap <leader>ag :<c-u>call AgOperator(visualmode())<cr>
function! AgOperator(type)
let saved_unamed_register = @@
if a:type ==# 'v'
execute "normal! `<v`>y"
elseif a:type ==# 'char'
execute "normal! `[v`]y"
else
return
endif
execute "Ag " . shellescape(@@)
let @@ = saved_unamed_register
endfunction
" highlight zsh-theme files as shell
au BufNewFile,BufRead *.zsh-theme set filetype=zsh
" Use all-space indentation, width of 2 spaces
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set list listchars=tab:\ \ ,trail:·
" Load colorscheme
colors jellybeans
" for outside high-contrast use
"Plugin "godlygeek/csapprox"
"colors github
" use system clipboard
set clipboard=unnamed
" Lose the GUI
if has("gui_running")
set guioptions=egmrt
set guifont=Menlo:h12
endif
" Show line numbers
set number
" zsh-style tab completion
set wildmenu
set wildmode=longest,list
set wildignore+=*vendor/*,*build/*,*bower_components/*,*node_modules/*,*-manifest.json,*.class,*ios/Pods/*
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" disable audible error bell
set visualbell
set history=2000 " keep 2000 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" Allow flipping between dirty buffers
set hidden
" Make searches case-insensive unless there is a capitalized char in the
" search
set ignorecase
set smartcase
" map \ to reverse character search
noremap \ ,
" shortcut to edit vimrc
nnoremap <leader>ev :vsplit ~/.vimrc<cr>
" shortcut to source vimrc
nnoremap <leader>sv :source ~/.vimrc<cr>
" open FZF with leader-t
nnoremap <leader>t :FZF<cr>
" Don't use Ex mode, use Q for formatting
map Q gq
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Deal with trailing whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
augroup whitespace
autocmd!
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
augroup end
" clear trailing spaces with <space><space>
nnoremap <silent> <space><space> :silent! %s/\s\+$//<CR>
" short keycode timeout to avoid cursor shape-change lag
" when leaving insert mode
set timeout timeoutlen=1000 ttimeoutlen=10
" don't blink cursor
set guicursor=n-v-c:block-blinkwait0-blinkon0-blinkoff0,i-ci-ve:ver25,r-cr:hor20,o:hor50
" Enable 256 colors to stop the CSApprox warning
if &term == 'xterm' || &term == 'screen'
set t_Co=256
endif
" renaming files in-place
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
execute ':saveas ' . new_name
execute ':silent !rm ' . old_name
redraw!
endif
endfunction
noremap <leader>n :call RenameFile()<cr>
" expand %% to current buffer's path in command line mode
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" remap W to save
command! -bang W w<bang>
" Reopen to last position in file.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
augroup lastposition
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup end
call vundle#end()
filetype plugin indent on
syntax on
set hlsearch
" move line up
nnoremap - ddp
" move line down
nnoremap _ ddkP
" upper 'case' word
nnoremap <c-u> viwU
" typo proof my life
iabbrev explict explicit
" wrap current word in quotes
nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
nnoremap <leader>' viw<esc>a'<esc>hbi'<esc>lel
" open last buffer in below + right split
nnoremap <leader>pb :execute "rightbelow vsplit " . bufname('#')<cr>
set noruler " disable ruler that shows line + col of cursor
set laststatus=2 " always show status line
nnoremap <leader>jpp :%!python3 -m json.tool<cr>
"
" LVSTHW
"
" wrap current word in single quotes
nnoremap <leader>' bi'<esc>ei'<esc>
noremap <leader>- ddp
noremap <leader>_ ddkP
" uppercase current word in insert mode
inoremap <c-u> <esc>bgUwea
"
" uppercase current word in normal mode
inoremap <c-u> bgUwe
function Varg(foo, ...)
echom a:foo
echom a:1
echo a:000
endfunction
" foo-bar;ls
" that's
"nnoremap <leader>g :silent execute ":grep! " . shellescape(expand("<cWORD>")) . " . " <cr>:copen<cr>
echo ">^.^<"