-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.vimrc
587 lines (438 loc) · 14.9 KB
/
.vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
filetype plugin indent on
" Reload vimrc immediately when saved.
autocmd! bufwritepost .vimrc source ~/.vimrc
set encoding=utf-8
set spelllang=en_us,cjk
set fileformat=unix
set background=light
" colorscheme PaperColor
let g:mapleader=','
""" Syntax and Indentation
syntax on
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
set smarttab
set autoindent " Copy indent from the previous row
set smartindent
set wrap
set scrolloff=2
set sidescrolloff=10
" Use <F2> to toggle paste mode
nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
set showmode
" Turn off auto-commenting
augroup all-files
autocmd!
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
augroup END
" Don't redraw screen during macro execution (makes them faster)
set lazyredraw
set showcmd
set nobackup
set ruler
set hidden
set wildmenu
set wildmode=list:longest
set wildignore+=*DS_Store*
set linebreak
set number
nnoremap <leader>n :set invnumber<CR>
nnoremap <leader>s :set spell!<CR>
""" Search Related Settings
" Search down into subdirectories
set path+=**
set hlsearch
noremap <silent> <C-l> :<C-u>nohlsearch<CR><C-l>
set incsearch
set showmatch
set ignorecase
set smartcase
" uppercase previously typed word and continue on.
inoremap <c-u> <esc>viwUea
set visualbell t_vb=
set novisualbell
set backspace=indent,eol,start
set complete-=i
set complete+=kspell
" set completeopt=menuone,preview,noinsert
set completeopt=menuone,preview
set ttimeout
set ttimeoutlen=100
set history=500
" Move up or down in column to next non-blank line.
nnoremap g<up> ?\%<C-R>=virtcol(".")<CR>v\S<CR>
nnoremap g<down> /\%<C-R>=virtcol(".")<CR>v\S<CR>
" Persistent Undo across sessions
set undofile
set undodir=$VIMDATA/undo
call mkdir(&undodir, 'p')
augroup vimrc
autocmd!
autocmd BufWritePre */tmp/* setlocal noundofile
augroup END
set display+=lastline
" Copies into Mac OS X clipboard for pasting.
set clipboard=unnamed
" Causes % to navigate XML tags and Ruby loops.
runtime macros/matchit.vim
" Request terminal version string (for xterm)
set t_RV=
" Do not display banner in Netrw (file browsing).
" See netrw-browse-maps for more info.
let g:netrw_banner=0
" Handle my common command typos.
cnoreabbrev <expr> W ((getcmdtype() is# ':' && getcmdline() is# 'W')?('w'):('W'))
" This doesn't do what I want, but at least it doesn't open up a file called "3" for editing.
cnoreabbrev <expr> e3 ((getcmdtype() is# ':' && getcmdline() is# 'e3')?(''):(''))
"" Visual star search ... make *|# act upon the current visual selection.
xnoremap * :<C-u>call <SID>VSetSearch()<CR>/<C-R>=@/<CR><CR>
xnoremap # :<C-u>call <SID>VSetSearch()<CR>?<C-R>=@/<CR><CR>
function! s:VSetSearch()
let s:temp = @s
norm! gv"sy
let @/ = '\V' . substitute(escape(@s, '/\'), '\n', '\\n', 'g')
let @s = s:temp
endfunction
" Push Quickfix list into args
command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames()
function! QuickfixFilenames()
let s:buffer_numbers = {}
for s:quickfix_item in getqflist()
let s:buffer_numbers[s:quickfix_item['bufnr']] = bufname(s:quickfix_item['bufnr'])
endfor
return join(map(values(s:buffer_numbers), 'fnameescape(v:val)'))
endfunction
" When editing a file, always jump to the last known cursor position.
augroup all-files
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
" Maintain some set-up between sessions
set sessionoptions=blank,buffers,curdir,help,resize,tabpages,winsize
"" Persistent Undo
if has('persistent_undo') && !isdirectory(expand('~').'/.vim/backups')
silent !mkdir ~/.vim/backups > /dev/null 2>&1
set undodir=~/.vim/backups
set undofile
endif
" Strip all trailing whitespace, but doesn't include MSWin Returns
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Strip double-spaces (like from a formatted paste)
nnoremap <leader>p :%s/\(\S \) \+/\1/g<CR>
set colorcolumn=98
highlight ColorColumn ctermbg=7 guifg=black
highlight rightMargin term=bold ctermfg=black guifg=brown
" Format XML
command! FormatXML :%!python3 -c "import xml.dom.minidom, sys; print(xml.dom.minidom.parse(sys.stdin).toprettyxml())"
" command! C14N11 :!xmllint --c14n11 %
nnoremap <leader>x :FormatXML<CR>
" Format JSON
nnoremap <leader>j :%!python3 -m json.tool<CR>1G=G<CR>:call FormatJSON()<CR>
nnoremap <leader>r :call FormatJSON()<CR>
function! FormatJSON()
" Make sure there are no tabs in the file.
if search("\t")
execute '%s/\t/ /g'
endif
" Move trailing [ to the next line.
if search(' \[\n\( *\) ')
execute '%s/ \[\n\( *\) /\r\1[ '
endif
" Move line-ending { to the next line.
if search('{\n *"')
execute '%s/{\n *"/{ "/'
endif
" Move trailing , to the next line.
if search(',\n\( *\) ')
execute '%s/,\n\( *\) /\r\1, /'
endif
" Move object-defining { to the next line.
if search('^\( *\)\([^{]*\): {')
execute '%s/^\( *\)\([^{]*\): {/\1\2:\r\1 {/g'
endif
" Move object-defining { to the next line. In while loop to capture depth.
while search('^\( *\)\(.[^{]*\): {')
execute '%s/^\( *\)\(.[^{]*\): {/\1\2:\r\1 {/g'
endwhile
" if search('\n\( *])\[ .*\n\1]')
" execute '%s#\n\( *\)\[ \(.*\)\n\1]# [ \2 ]#'
" endif
endfunction
" Insert the current date
nnoremap <leader>d "=strftime("%Y-%m-%d")<CR>p
" Force save when using a read-only file
cnoremap sudow w !sudo dd of=%
" Use j and k to navigate pop-up (omnicomplete).
inoremap <expr> j ((pumvisible())?("\<C-n>"):("j"))
inoremap <expr> k ((pumvisible())?("\<C-p>"):("k"))
let g:markdown_fenced_languages = ['bash', 'shell=bash', 'sql', 'html', 'css', 'javascript', 'js=javascript', 'json=javascript', 'clojure', 'erlang', 'ruby', 'eruby', 'erb=eruby', 'vim', 'xml', 'yaml']
""" Slime
let g:slime_target = 'tmux'
let g:slime_paste_file = expand("$HOME/.slime_paste")
" let g:slime_paste_file = tempname()
" This allows slime to work with tmate!
let g:slime_default_config = {"socket_name": get(split($TMUX, ","), 0), "target_pane": ":.1"}
""" Hg options
augroup mercurial
autocmd!
autocmd FileType hgcommit setlocal spell textwidth=72
augroup END
""" Git options
augroup git
autocmd!
autocmd FileType gitcommit setlocal spell textwidth=72
augroup END
" function! s:Branch()
" let s:branch = system("git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* //'")
" if branch != ''
" return substitute(substitute(branch, '\n', '', 'g'), 'daines.', '', 'g')
" en
" return ''
" endfunction
" Output branch name to the second line of the commit message.
" command! -nargs=0 Branch put=s:Branch()
" autocmd FileType gitcommit Branch
" autocmd FileType gitcommit execute "normal ggO"
""" Erlang options.
augroup erlang
autocmd!
autocmd BufRead,BufNewFile *.erl,*.es.*.hrl,*.yaws,*.xrl set expandtab
autocmd BufNewFile,BufRead *.erl,*.es,*.hrl,*.yaws,*.xrl setf erlang
" Highlight when a comma is not followed by a space.
autocmd FileType erlang match SyntaxHighlight /,[ \n]\@!/
" Highlight when a pipe is not surrounded by spaces.
" autocmd FileType erlang match SyntaxHighlight /[ |]\@!|[ |]\@!/
augroup END
highlight SyntaxHighlight ctermbg=darkblue guibg=darkblue
set wildignore+=*.so,*.swp,*.beam
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.git$',
\ 'file': '\v\.(beam|png|jpg)$',
\ }
""" Clojure options.
let g:clj_highlight_builtins = 1
let g:clojure_special_indent_words = 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn,defcomponent'
let g:clojure_fuzzy_indent_patterns = ['^with', '^def', '^let', '^for-all']
" Don't stop indentation fixes at 100 lines.
let g:clojure_maxlines = 1000
" Causes 1-space indent if there is no argument after a function.
" let g:clojure_align_subforms = 1
augroup clojure
autocmd!
autocmd BufWritePre *.clj :%s/\s\+$//e
autocmd BufWritePre *.clj :%s/\t/ /ge
autocmd FileType clojure setlocal textwidth=78
autocmd FileType clojure setlocal lispwords+=fdef
autocmd BufNewFile,BufReadPost .lein-env set filetype=clojure
augroup END
set wildignore+=*/target/*
" TODO Make this only applicable if editing a Clojure file?
" nnoremap <leader>c :call AddClojureNamespace()<CR>
function! AddClojureNamespace()
let s:ns = ["(ns " . fnamemodify(expand('%'), ':r:s#^src/##:s#^test/##:gs#/#.#:gs#_#-#')]
if (expand('%') =~ "test/")
let s:under_test = fnamemodify(expand('%'), ':r:s#^test/##:s#_test$##:gs#/#.#:gs#_#-#')
let s:as_var = split(s:under_test, '\.')[-1]
call add(s:ns, ' "Tests against the ' . s:under_test . ' namespace."')
call add(s:ns, " (:require [clojure.test :refer [deftest is testing]]")
call add(s:ns, " [" . s:under_test . " :as " . s:as_var . "]))")
else
call add(s:ns, ' "TODO: Write a clear explanation of what purpose this namespace serves."')
call add(s:ns, " (:require [clojure.spec.alpha :as s]))")
endif
call add(s:ns, "")
let s:failed = append(0, s:ns)
if (s:failed)
echo "Problem creating namespace!"
else
let &modified = 1
endif
endfunction
" nnoremap <leader>e :call FormatEDN()<CR>1G=G<CR>
function! FormatEDN()
" TODO: There are better tools for this, just plug into them (joker?)
" Separate sequences of strings to separate lines.
if search('" "')
execute '%s/" "/"\r"/g'
endif
" Break lists of maps onto separate lines.
if search('} {')
execute '%s/} {/}\r{/g'
endif
" Convert commas into newlines in maps.
if search(', :')
execute '%s/, :/\r:/g'
endif
endfunction
"" Elixir
augroup elixir
autocmd FileType elixir setlocal textwidth=98
augroup END
nnoremap <leader>z :call OpenElixirTestFile()<CR>
function! OpenElixirTestFile()
let s:ns = fnamemodify(expand('%'), ':r:s#lib#test#') . '_test.exs'
execute "edit " . s:ns
endfunction
"" sexp
nnoremap <Space> <Nop>
let g:maplocalleader=' '
"" iced
" Enable vim-iced's default key mapping
let g:iced_enable_default_key_mappings = v:true
" Automatically display expected arguments to the right
" let g:iced_enable_auto_document = 'every'
""" Ruby Options
" Allows gf to jump to Ruby requires.
set suffixesadd+=.rb
augroup ruby
autocmd!
autocmd BufWritePre *.rb :%s/\s\+$//e
autocmd BufWritePre *.rb :%s/\t/ /ge
" autoindent with two spaces, always expand tabs
autocmd FileType ruby,yaml set ai sw=2 sts=2 et
" treat thor files as Ruby
autocmd BufNewFile,BufReadPost *.thor set filetype=ruby
autocmd BufRead,BufNewFile *.thor set filetype=ruby
autocmd BufRead,BufNewFile *.jbuilder set filetype=ruby
autocmd BufWritePre *.rb :%s/\s\+$//e
augroup END
compiler ruby
""" Text options
augroup text
autocmd!
autocmd FileType text setlocal nosmartindent
autocmd FileType text :set spl=en_us spell
" Force markdown over modula2
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
autocmd BufRead,BufNewFile *.md set filetype=markdown
autocmd FileType markdown setlocal spell
autocmd BufRead,BufNewFile *.md setlocal textwidth=78
augroup END
iabbrev teh the
" Wrap selection with quotation marks.
vnoremap <leader>" <esc>`>a"<esc>`<i"<esc>
vnoremap <leader>' <esc>`>a'<esc>`<i'<esc>
vnoremap <leader>` <esc>`>a`<esc>`<i`<esc>
nnoremap <leader>" viw<esc>`>a"<esc>`<i"<esc>
nnoremap <leader>' viw<esc>`>a'<esc>`<i'<esc>
nnoremap <leader>` viw<esc>`>a`<esc>`<i`<esc>
vnoremap <leader>i <esc>`>a*<esc>`<i*<esc>
vnoremap <leader>b <esc>`>a**<esc>`<i**<esc>
""" HTML Options
augroup html
autocmd!
autocmd BufNewFile *.html source ~/.vim/ftplugin/htmltemplate.vim
augroup END
""" JavaScript Options
augroup javascript
autocmd!
autocmd BufNewFile,BufRead *.json setf javascript
augroup END
""" PHP Options
augroup php
" set expandtab tabstop=4 shiftwidth=4 softtabstop=4
augroup END
""" TagList Options
let g:Tlist_Use_Right_Window=1
let g:Tlist_Enable_Fold_Column=0
let g:Tlist_Show_One_File=1 " especially with this one
let g:Tlist_Compact_Format=1
let g:Tlist_Ctags_Cmd='/usr/local/bin/ctags'
set updatetime=1000
nmap ,t :!(cd %:p:h;ctags *)& " Maps the updates of tags to key ,t.
set tags=tags; " The ';' at the end will cause the ctags plugin to search for current dir and above dirs until it find a tag file.
nnoremap <leader>T :TlistToggle<CR>
nnoremap <f5> :!ctags -R<CR> " Refresh ctags
let g:gutentags_cache_dir = '~/.tags_cache'
""" Elm Options
let g:elm_format_autosave=1
""" Nerdcommenter
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
let g:NERDDefaultAlign = 'left'
""" VimL and Vader (for Exercism)
function! s:exercism_tests()
if expand('%:e') ==? 'vim'
let s:testfile = printf('%s/%s.vader', expand('%:p:h'),
\ tr(expand('%:p:h:t'), '-', '_'))
if !filereadable(s:testfile)
echoerr 'File does not exist: '. s:testfile
return
endif
source %
execute 'Vader' s:testfile
else
let s:sourcefile = printf('%s/%s.vim', expand('%:p:h'),
\ tr(expand('%:p:h:t'), '-', '_'))
if !filereadable(s:sourcefile)
echoerr 'File does not exist: '. s:sourcefile
return
endif
execute 'source' s:sourcefile
Vader
endif
endfunction
augroup exercism
autocmd BufRead *.{vader,vim}
\ command! -buffer Test call s:exercism_tests()
augroup END
""" ALE
" Enable completion where available.
let g:ale_completion_enabled = 1
" Enable alex for all files
let g:ale_alex_use_global = 1
" Navigate to ALE errors.
nmap <silent> <C-k> <Plug>(ale_previous)
nmap <silent> <C-j> <Plug>(ale_next)
" Only lint on save.
let g:ale_lint_on_text_changed = 'never'
" PHP settings
let g:ale_php_phpstan_level = '7'
let g:phpstan_analyse_level = '7'
let g:ale_linters = {
\ 'elixir': ['elixir-ls', 'credo'],
\ 'rust': ['rust-analyzer'],
\}
let b:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'elixir': ['mix_format'],
\ 'javascript': ['prettier', 'eslint'],
\ 'rust': ['rustfmt'],
\}
let g:ale_elixir_elixir_ls_release = expand("/Users/daines/src/elixir-ls/release/")
let g:ale_elixir_credo_strict = 1
" let g:ale_elixir_elixir_ls_config = {'elixirLS': {'dialyzerEnabled': v:false}
let g:ale_sign_error = '✘'
" let g:ale_sign_warning = '⚠'
" highlight ALEErrorSign ctermbg=NONE ctermfg=red
" highlight ALEWarningSign ctermbg=NONE ctermfg=yellow
let g:ale_lint_on_save = 1
let g:ale_fix_on_save = 1
noremap <leader>ad :ALEGoToDefinition<CR>
nnoremap <leader>af :ALEFix<CR>
noremap <leader>ar :ALEFindReferences<CR>
nnoremap <leader>K :ALEHover<CR>
""" fzf (fuzzy finder)
set runtimepath+=/usr/local/bin/fzf
nnoremap <C-p> :<C-u>FZF<CR>
""" Grepper
let g:grepper = {}
" let g:grepper.tools = ['rg', 'git, 'grep']
let g:grepper.tools = ['rg']
" Search for the current word.
nnoremap <leader>* :Grepper -cword -noprompt<CR>
" Search for the current selection.
nmap gs <plug>(GrepperOperator)
xmap gs <plug>(GrepperOperator)
" Put these lines at the very end of your vimrc file.
" Load all plugins now.
" Plugins need to be added to runtimepath before helptags can be generated.
packloadall
" Load all of the helptags now, after plugins have been loaded.
" All messages and errors will be ignored.
silent! helptags ALL