-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
561 lines (464 loc) · 15.2 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
" For a paranoia.
" Normally `:set nocp` is not needed, because it is done automatically
" when .vimrc is found.
if &compatible
" `:set nocp` has many side effects. Therefore this should be done
" only when 'compatible' is set.
set nocompatible
endif
set shell=/bin/sh
filetype off
" force reload of ftdetect files
filetype plugin indent on
set mouse=a
" hide buffers instead of closing them
set hidden
" use correct amount of spaces for a tab in insert mode
set expandtab
" a tab is two spaces
set tabstop=2
set softtabstop=2
" number of spaces to use for autoindenting
set shiftwidth=2
" use multiple of shiftwidth when indenting with '<' and '>'
set shiftround
" avoid modeline vulnerabilities
set modelines=0
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" insert tabs on the start of a line according to shiftwidth, not tabstop
set smarttab
" copies indentation from previous line
set autoindent
" copy the previous indentation on autoindenting
set copyindent
" always show line numbers
set number
" set show matching parenthesis
set showmatch
" ignore case when searching
set ignorecase
" ignore case if search pattern is all lowercase, case-sensitive otherwise
set smartcase
" highlight search terms
set hlsearch
" show search matches as you type
set incsearch
" remember more commands and search history
set history=1000
" use many muchos levels of undo
set undolevels=1000
set wildignore+=*.swp,*.bak,*.pyc,*.class,.git,node_modules/**,**Godeps
set wildignore+=*Godeps
" change the terminal's title
set title
" don't beep
set novisualbell
" don't beep
set noerrorbells
" prevent auto indentation when pasting
set pastetoggle=<F2>
" font family & size
set guifont=PragmataProLiga-Regular:h18
" use utf-8 everywhere
set encoding=utf-8
" minimal lines to kepp above and below screen
set scrolloff=3
" display the mode you're in.
set showmode
" display incomplete commands.
set showcmd
" enhanced completion
set wildmenu
" enhanced completion
set wildmode=list:longest
" disable folding
set nofoldenable
" highlight the line of the cursor
" set cursorline
" avoid excessive redraws
set lazyredraw
" smooth and fast redrawing
set ttyfast
" show line and column info
set ruler
" wrap text if longer than window width
set wrap
" max text insertion width before breakage
set textwidth=79
" description of automatic formatting
set formatoptions=qrn1
" auto-save the file on different commands
set autowriteall
" Suffixes that get lower priority when doing tab completion for filenames.
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.pyc,.class,.jar
" EOL for current buffer
set fileformat=unix
" list of EOL formats to try
set fileformats=unix,dos,mac
" store history information
set viminfo=!,'50,\"1000,:150,n~/.vim/viminfo
" always show signcolumns
set signcolumn=yes
" better display of messages
set cmdheight=3
" smaller updatetime for CursorHold & CursorHoldI
set updatetime=300
" split at the bottom
set splitbelow
" some file watching tools will miss an rename and replace
set backupcopy=yes
" autoread changed files
set autoread
au FocusGained * :checktime
"" backup/swap/undo
" enable backups
set backup
" backup file directory
set backupdir=~/.vim/tmp/backup/
" swap file directory
set directory=~/.vim/tmp/swap/
" undo file directory
if exists('+undodir')
set undodir=~/.vim/tmp/undo/
endif
" backup before overwritting
set writebackup
" show status line
set laststatus=2
set statusline=
" file name
set statusline +=%t
" modified flag
set statusline +=\ %#todo#%m%*
" right aligned from here
set statusline +=%=
" current line/total lines and column
set statusline +=[%3l/%-3L\|%-2c]
" file type
set statusline +=\ %Y
" Set python paths explicitly under macOS.
if has('macunix')
let g:python2_host_prog = '/usr/local/bin/python'
let g:python3_host_prog = '/usr/local/bin/python3'
endif
" switch syntax highlighting on, when the terminal has colors
if &t_Co > 2
syntax enable
syntax sync fromstart
endif
" change the mapleader from \ to ,
let mapleader=","
" spare extra modifier key for commands
nnoremap ; :
" quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<cr>
nmap <silent> <leader>sv :so $MYVIMRC<cr>
" force home row usage
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
" step line by line even when text is wrapped
nnoremap j gj
nnoremap k gk
" clear search highlights
nmap <silent> <leader><space> :nohlsearch<cr>
" use w!! to use sudo after opening
cmap w!! w !sudo tee % > /dev/null
" prevent vim regex handling
nnoremap / /\v
vnoremap / /\v
" shortcut to rapidly toggle `set list`
nmap <leader>l :set list!<cr>
" remap help file
inoremap <F1> <ESC>
" escape from insert mode
inoremap jk <ESC>
" quickfix navigation
map <C-n> :lnext<cr>
map <C-m> :lprevious<cr>
nnoremap <leader>a :LToggle<cr>
" map make
nmap <leader>m :make!<cr>
" remember cursor position
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
" Per file-type indentation
au FileType haskell setlocal sts=4 sw=4 expandtab
au FileType elm setlocal sts=4 sw=4 expandtab
au FileType javascript setlocal fo=cqt sts=2 sw=2 tw=80 wm=0 expandtab
au FileType css setlocal ts=2 sw=2 noexpandtab
au FileType go setlocal ts=4 sw=4 noexpandtab
au BufNewFile,BufRead,FileType *.go setlocal ts=4 sw=4 noexpandtab
au FileType c,cpp,glsl setlocal ts=8 sw=8 noexpandtab
au FileType lua setlocal sw=4 expandtab
au FileType sh,zsh setlocal ts=2 sw=2 noexpandtab
au FileType vim,ruby setlocal sts=2 sw=2 expandtab
au FileType help setlocal ts=4 sw=4 noexpandtab
au FileType txt setlocal noai nocin nosi inde= wrap linebreak
au FileType pandoc setlocal nonumber
au FileType markdown setlocal nonumber
au FileType fountain setlocal nonumber noai nocin nosi inde= wrap linebreak
au BufNewFile,BufReadPost *.md set filetype=markdown
au BufNewFile,BufRead *.tsx,*.jsx set filetype=typescriptreact
augroup configgroup
autocmd!
"Set Pollen syntax for files with these extensions:
au! BufRead,BufNewFile *.p set filetype=pollen
au! BufRead,BufNewFile *.pm set filetype=pollen
au! BufRead,BufNewFile *.pp set filetype=pollen
au! BufRead,BufNewFile *.ptree set filetype=pollen
" Suggested editor settings:
autocmd FileType pollen setlocal wrap " Soft wrap (don't affect buffer)
autocmd FileType pollen setlocal linebreak " Wrap on word-breaks only
augroup END
" rust.vim sets the filetype for Cargo.toml to cfg, which confuses vim-toml
au BufNewFile,BufRead *.toml,Gopkg.lock,Cargo.lock,*/.cargo/config,*/.cargo/credentials,Pipfile setf toml
" plugin management with minpac
function! PackInit() abort
packadd minpac
if exists('*minpac#init')
call minpac#init()
call minpac#add('k-takata/minpac', {'type': 'opt'})
" comments
call minpac#add('tpope/vim-commentary')
" git
" call minpac#add('mhinz/vim-signify')
" navigation
call minpac#add('cloudhead/neovim-fuzzy')
call minpac#add('jremmen/vim-ripgrep')
" intellisense
call minpac#add('Shougo/denite.nvim')
call minpac#add('neoclide/coc.nvim', {'branch': 'master', 'do': 'call coc#util#install()'})
" elm
call minpac#add('w0rp/ale')
call minpac#add('elmcast/elm-vim')
" toml
call minpac#add('cespare/vim-toml')
" glsl
call minpac#add('tikhomirov/vim-glsl')
" go
call minpac#add('fatih/vim-go')
" graphql
call minpac#add('jparise/vim-graphql')
" latex
call minpac#add('lervag/vimtex')
" pico8
" call minpac#add('justinj/vim-pico8-syntax')
" purescript
" call minpac#add('purescript-contrib/purescript-vim')
" call minpac#add('FrigoEU/psc-ide-vim')
" call minpac#add('vim-syntastic/syntastic')
" ocaml/reason
call minpac#add('reasonml-editor/vim-reason-plus')
call minpac#add('sbdchd/neoformat')
" one
call minpac#add('rakr/vim-one')
" racket
call minpac#add('otherjoel/vim-pollen')
call minpac#add('wlangstroth/vim-racket')
" rst
call minpac#add('gu-fan/riv.vim')
" rust
call minpac#add('rust-lang/rust.vim')
" shady
call minpac#add('cloudhead/shady.vim')
" solidity
call minpac#add('tomlion/vim-solidity')
" svelte
call minpac#add('leafgarland/typescript-vim')
call minpac#add('evanleck/vim-svelte')
" terraform
call minpac#add('hashivim/vim-terraform')
" call minpac#add('juliosueiras/vim-terraform-completion')
" typescript
call minpac#add('peitalin/vim-jsx-typescript')
" writer
call minpac#add('junegunn/goyo.vim')
call minpac#add('junegunn/limelight.vim')
call minpac#add('reedes/vim-colors-pencil')
call minpac#add('subnut/vim-iawriter')
call minpac#add('preservim/vim-pencil')
" move
call minpac#add('rvmelkonian/move.vim')
" fish
call minpac#add('dag/vim-fish')
" protobuf
call minpac#add('uarun/vim-protobuf')
" d2
call minpac#add('terrastruct/d2-vim')
endif
endfunction
command! PackClean call PackInit() | call minpac#clean()
command! PackStatus call PackInit() | call minpac#status()
command! PackUpdate call PackInit() | call minpac#update('', {'do': 'call minpac#status()'})
" Plugins need to be added to runtimepath before helptags can be generated.
packloadall
" Load all of the helptags now, after plugins have been loaded.
" Ignore all messages and errors.
silent! helptags ALL
" colors
try
colorscheme shady
set background=dark
catch
endtry
" comments
nmap <C-_> <Plug>CommentaryLine
xmap <C-_> <Plug>Commentary
" fuzzy
nnoremap <leader>o :FuzzyOpen<cr>
nnoremap <leader>f :FuzzyGrep<cr>
" vim-commentary
nmap <C-_> gcc
xmap <C-_> gc
" ripgrep
if executable('rg')
let g:ackprg = 'rg --vimgrep --no-heading'
set grepprg=rg\ --vimgrep
endif
" ListToggle
let g:lt_location_list_toggle_map = '<leader>a'
let g:lt_height = 5
" intellisense
" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" 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>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" use <c-space>for trigger completion
imap <c-space> coc#refresh()
" Use <cr> for confirm completion.
" Coc only does snippet and additional edit on confirm.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" use <c-space>for trigger completion
imap <c-space> coc#refresh()
" shortcuts for rakcet & pollen
imap <C-L> λ
imap <C-E> ◊
autocmd! CompleteDone * if pumvisible() == 0 | pclose | endif
" Remap keys for gotos
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 for show documentation in preview window
nnoremap <silent> K :call <sid>show_documentation()<cr>
function! s:show_documentation()
if &filetype == 'vim'
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
command! -nargs=0 Prettier :call CocAction('runCommand', 'prettier.formatFile')
" Show diagnostics of current workspace
nnoremap <silent> <space>a :<C-u>Denite coc-diagnostic<cr>
" TODO list
command! Todo Rg 'TODO'
command! TodoLocal Rg 'TODO' %
nnoremap <leader>tg :Todo<cr>
nnoremap <leader>tl :TodoLocal<cr>
" elm
let g:elm_jump_to_error = 1
let g:elm_make_show_warnings = 1
let g:elm_detailed_complete = 1
let g:elm_format_autosave = 1
let g:elm_format_fail_silently = 0
let g:elm_setup_keybindings = 1
" go
let g:go_fmt_command = "goimports"
let g:go_gopls_enabled = 1
" ocaml/reason
let g:neoformat_enabled_ocaml = ['ocamlformat']
" purs
let g:psc_ide_syntastic_mode = 1
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
" rst
let g:riv_auto_format_table = 0
let g:riv_fold_auto_update = 0
" rust
let g:rustfmt_autosave = 1
let g:rustfmt_emit_files = 1
let g:rustfmt_command = 'rustfmt +nightly'
" terraform
let g:terraform_align=1
let g:terraform_fmt_on_save=1
" vimtex
let g:vimtex_view_general_viewer = 'mupdf'
let g:vimtex_view_general_options
\ = '-reuse-instance -forward-search @tex @line @pdf'
" let g:vimtex_view_general_options_latexmk = '-reuse-instance'
let g:tex_flavor = 'xelatex'
let g:tex_conceal = ''
let g:vimtex_fold_manual = 1
let g:vimtex_compiler_latexmk = {
\ 'executable' : 'latexmk',
\ 'options' : [
\ '-xelatex',
\ '-file-line-error',
\ '-synctex=1',
\ '-interaction=nonstopmode',
\ ],
\}
nnoremap <leader>c :VimtexCompile<cr>
" writer
let g:pencil_higher_contrast_ui = 1
" custom highlight
" hi User1 ctermbg=black ctermfg=red guibg=black guifg=red
hi CocErrorSign ctermfg=red guibg=black guifg=red
hi CocWarningSign ctermfg=yellow guibg=black guifg=yello
" CoC
hi link CocErrorVirtualText Error
hi link CocErrorSign Error
hi CocErrorHighlight cterm=undercurl guisp=#B03060
hi link CocErrorFloat Error
hi link CocWarningVirtualText Warning
hi link CocWarningSign Warning
hi CocWarningHighlight cterm=undercurl guisp=#FFE4B5
hi link CocInfoVirtualText Alternative
hi link CocInfoSign Alternative
hi CocInfoHighlight cterm=underline guisp=blue
hi link CocHintVirtualText Alternative
hi link CocHintSign Alternative
hi CocHintHighlight cterm=none guisp=blue
hi CocUnusedHighlight ctermfg=246 cterm=strikethrough
hi link CocRustChainingHint Hint
" These only use an 'undercurl'. The colors used are
" 'maroon' and 'moccasin'.
hi link CocHintSign Hint
hi link CocCodeLens DarkGrey
hi link CocFloating Pmenu
" helper functions
command! LToggle call s:LListToggle()
function! s:LListToggle() abort
let buffer_count_before = s:BufferCount()
" Location list can't be closed if there's cursor in it, so we need
" to call lclose twice to move cursor to the main pane
silent! lclose
silent! lclose
if s:BufferCount() == buffer_count_before
execute "silent! lopen 10"
endif
endfunction
function! s:BufferCount() abort
return len(filter(range(1, bufnr('$')), 'buflisted(v:val)'))
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
nmap <c-a> <Plug>(coc-codeaction)