-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
573 lines (471 loc) · 17.4 KB
/
vimrc
File metadata and controls
573 lines (471 loc) · 17.4 KB
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
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'yous/vim-open-color'
Plugin 'jnurmine/Zenburn'
Plugin 'reasonml-editor/vim-reason-plus'
Plugin 'gilgigilgil/anderson.vim'
Plugin 'ajmwagar/vim-deus'
Plugin 'victorze/foo'
Plugin 'xuhdev/vim-latex-live-preview'
Plugin 'artur-shaik/vim-javacomplete2'
Plugin 'udalov/kotlin-vim'
Plugin 'skywind3000/asyncrun.vim'
Plugin 'kien/ctrlp.vim'
Plugin 'scrooloose/nerdcommenter'
Plugin 'AndrewRadev/splitjoin.vim'
Plugin 'ConradIrwin/vim-bracketed-paste'
Plugin 'cespare/vim-toml'
Plugin 'corylanou/vim-present', {'for' : 'present'}
Plugin 'ekalinin/Dockerfile.vim', {'for' : 'Dockerfile'}
Plugin 'elzr/vim-json', {'for' : 'json'}
Plugin 'fatih/vim-hclfmt'
Plugin 'fatih/vim-nginx' , {'for' : 'nginx'}
Plugin 'godlygeek/tabular'
Plugin 'hashivim/vim-hashicorp-tools'
Plugin 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
Plugin 'junegunn/fzf.vim'
Plugin 'mileszs/ack.vim'
Plugin 'plasticboy/vim-markdown'
Plugin 'scrooloose/nerdtree'
Plugin 't9md/vim-choosewin'
Plugin 'roxma/vim-tmux-clipboard'
Plugin 'tmux-plugins/vim-tmux', {'for': 'tmux'}
Plugin 'tmux-plugins/vim-tmux-focus-events'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-eunuch'
Plugin 'tpope/vim-repeat'
Plugin 'tpope/vim-scriptease'
Plugin 'ervandew/supertab'
Plugin 'lervag/vimtex'
Plugin 'huyvohcmc/atlas.vim'
Plugin 'rust-lang/rust.vim'
Plugin 'preservim/tagbar'
Plugin 'mindriot101/vim-yapf'
Plugin 'Chiel92/vim-autoformat'
Plugin 'dense-analysis/ale'
Plugin 'prabirshrestha/async.vim'
Plugin 'prabirshrestha/vim-lsp'
Plugin 'prabirshrestha/asyncomplete.vim'
Plugin 'prabirshrestha/asyncomplete-lsp.vim'
Plugin 'scrooloose/syntastic'
Plugin 'dart-lang/dart-vim-plugin'
Plugin 'prettier/vim-prettier'
Plugin 'neoclide/coc.nvim'
Plugin 'neovimhaskell/haskell-vim'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
"=====================================================
"===================== SETTINGS ======================
set encoding=utf-8 " Set default encoding to UTF-8
set autoread " Automatically reread changed files without asking me anything
set autoindent
set smartindent
" set shiftwidth=4 " Sets indent width to be consistent with netbeans:
set backspace=indent,eol,start " Makes backspace key more powerful.
set incsearch " Shows the match while typing
set hlsearch " Highlight found searches
set clipboard=unnamed " Changes default clipboard to system
"set mouse=a "Enable mouse mode
" Disables automatic comment insertion for newlines
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
set noerrorbells " No beeps
set number " Show line numbers
set showcmd " Show me what I'm typing
set noswapfile " Don't use swapfile
set nobackup " Don't create annoying backup files
set splitright " Split vertical windows right to the current windows
set splitbelow " Split horizontal windows below to the current windows
set autowrite " Automatically save before :next, :make etc.
set hidden
set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
set noshowmatch " Do not show matching brackets by flickering
set noshowmode " We show the mode with airline or lightline
set ignorecase " Search case insensitive...
set smartcase " ... but not it begins with upper case
set completeopt=menu,menuone
set nocursorcolumn " speed up syntax highlighting
set nocursorline
set updatetime=300
set pumheight=10 " Completion window max size
set conceallevel=2 " Concealed text is completely hidden
set shortmess+=c " Shut off completion messages
set belloff+=ctrlg " If Vim beeps during completion
" Cursor highlighting options
highlight Cursor guifg=#B0F566 guibg=#B0F566
highlight iCursor guifg=#B0F566 guibg=#B0F566
set guicursor=n-v-c:block-Cursor
set guicursor+=i:ver100-iCursor
set guicursor+=n-v-c:blinkon0
set guicursor+=i:blinkwait10
" increase max memory to show syntax highlighting for large files
set maxmempattern=20000
" ~/.viminfo needs to be writable and readable. Set oldfiles to 1000 last
" recently opened files, :FzfHistory uses it
set viminfo='1000
if has('persistent_undo')
set undofile
set undodir=~/.cache/vim
endif
" Colorscheme settings
" set background=dark
" colorscheme deus
set t_Co=256
" Use 24-bit (true-color) mode in Vim/Neovim when outside tmux or screen.
" If you're using tmux version 2.2 or later, you can remove the outermost $TMUX
" check and use tmux's 24-bit color support
" (http://sunaku.github.io/tmux-24bit-color.html#usage for more information.)
if empty($TMUX) && empty($STY)
" See https://gist.github.com/XVilka/8346728.
if $COLORTERM =~# 'truecolor' || $COLORTERM =~# '24bit'
if has('termguicolors')
" See :help xterm-true-color
if $TERM =~# '^screen'
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
set termguicolors
endif
endif
endif
syntax enable
"=====================================================
"===================== STATUSLINE ====================
" Always show the status line
set laststatus=2
let s:modes = {
\ 'n': 'NORMAL',
\ 'i': 'INSERT',
\ 'R': 'REPLACE',
\ 'v': 'VISUAL',
\ 'V': 'V-LINE',
\ "\<C-v>": 'V-BLOCK',
\ 'c': 'COMMAND',
\ 's': 'SELECT',
\ 'S': 'S-LINE',
\ "\<C-s>": 'S-BLOCK',
\ 't': 'TERMINAL'
\}
let s:prev_mode = ""
function! StatusLineMode()
let cur_mode = get(s:modes, mode(), '')
" do not update higlight if the mode is the same
if cur_mode == s:prev_mode
return cur_mode
endif
if cur_mode == "NORMAL"
exe 'hi! StatusLine ctermfg=236'
exe 'hi! myModeColor cterm=bold ctermbg=148 ctermfg=22'
elseif cur_mode == "INSERT"
exe 'hi! myModeColor cterm=bold ctermbg=23 ctermfg=231'
elseif cur_mode == "VISUAL" || cur_mode == "V-LINE" || cur_mode == "V_BLOCK"
exe 'hi! StatusLine ctermfg=236'
exe 'hi! myModeColor cterm=bold ctermbg=208 ctermfg=88'
endif
let s:prev_mode = cur_mode
return cur_mode
endfunction
function! StatusLineFiletype()
return winwidth(0) > 70 ? (strlen(&filetype) ? &filetype : 'no ft') : ''
endfunction
function! StatusLinePercent()
return (100 * line('.') / line('$')) . '%'
endfunction
exe 'hi! myInfoColor ctermbg=240 ctermfg=252'
" start building our statusline
set statusline=
" mode with custom colors
set statusline+=%#myModeColor#
set statusline+=%{StatusLineMode()}
set statusline+=%*
" left information bar (after mode)
set statusline+=%#myInfoColor#
set statusline+=\ %*
" right section seperator
set statusline+=%=
" filetype, percentage, line number and column number
set statusline+=%#myInfoColor#
set statusline+=\ %{StatusLineFiletype()}\ %{StatusLinePercent()}\ %l:%v
set statusline+=\ %*
"=====================================================
"===================== MAPPINGS ======================
" This comes first, because we have mappings that depend on leader
" With a map leader it's possible to do extra key combinations
" i.e: <leader>w saves the current file
let mapleader = ","
" Some useful quickfix shortcuts for quickfix
map <C-n> :cn<CR>
map <C-m> :cp<CR>
nnoremap <leader>a :cclose<CR>
" Fast saving
nnoremap <leader>w :w!<cr>
nnoremap <silent> <leader>q :q!<CR>
" Center the screen
nnoremap <space> zz
" Remove search highlight
nnoremap <leader><space> :nohlsearch<CR>
function! s:clear_highlight()
let @/ = ""
call go#guru#ClearSameIds()
endfunction
nnoremap <silent> <leader><space> :<C-u>call <SID>clear_highlight()<CR>
" Source the current Vim file
nnoremap <leader>pr :Runtime<CR>
" Close all but the current one
nnoremap <leader>o :only<CR>
" Better split switching
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Print full path
map <C-p> :echo expand("%:p")<cr>
" Visual linewise up and down by default (and use gj gk to go quicker)
noremap <Up> gk
noremap <Down> gj
noremap j gj
noremap k gk
" Exit on j
imap jj <Esc>
" Source (reload configuration)
nnoremap <silent> <F5> :source $MNVIMRC<CR>
nnoremap <F6> :setlocal spell! spell?<CR>
" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
nnoremap n nzzzv
nnoremap N Nzzzv
" Same when moving up and down
noremap <C-d> <C-d>zz
noremap <C-u> <C-u>zz
" Remap H and L (top, bottom of screen to left and right end of line)
nnoremap H ^
nnoremap L $
vnoremap H ^
vnoremap L g_
" Act like D and C
nnoremap Y y$
" Do not show stupid q: window
map q: :q
" Don't move on * I'd use a function for this but Vim clobbers the last search
" when you're in a function so fuck it, practicality beats purity.
nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
" mimic the behavior of /%Vfoobar which searches within the previously
" selected visual selection
" while in search mode, pressing / will do this
vnoremap / <Esc>/\%><C-R>=line("'<")-1<CR>l\%<<C-R>=line("'>")+1<CR>l
vnoremap ? <Esc>?\%><C-R>=line("'<")-1<CR>l\%<<C-R>=line("'>")+1<CR>l
" Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
if !has('gui_running')
set notimeout
set ttimeout
set ttimeoutlen=10
augroup FastEscape
autocmd!
au InsertEnter * set timeoutlen=0
au InsertLeave * set timeoutlen=1000
augroup END
endif
" Visual Mode */# from Scrooloose {{{
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o>
" create a go doc comment based on the word under the cursor
function! s:create_go_doc_comment()
norm "zyiw
execute ":put! z"
execute ":norm I// \<Esc>$"
endfunction
nnoremap <leader>ui :<C-u>call <SID>create_go_doc_comment()<CR>
"===================== PLUGINS ======================
" plugins expect bash - not fish, zsh, etc
set shell=bash
" use goimports for formatting
let g:go_fmt_command = "goimports"
" turn highlighting on
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:syntastic_go_checkers = ['go', 'golint', 'errcheck']
let g:go_modifytags_transform = 'camelcase'
let g:go_fold_enable = []
nmap <C-g> :GoDecls<cr>
imap <C-g> <esc>:<C-u>GoDecls<cr>
" Open go doc in vertical window, horizontal, or tab
au Filetype go nnoremap <leader>v :vsp <CR>:exe "GoDef" <CR>
au Filetype go nnoremap <leader>s :sp <CR>:exe "GoDef"<CR>
au Filetype go nnoremap <leader>t :tab split <CR>:exe "GoDef"<CR>
" run :GoBuild or :GoTestCompile based on the go file
function! s:build_go_files()
let l:file = expand('%')
if l:file =~# '^\f\+_test\.go$'
call go#test#Test(0, 1)
elseif l:file =~# '^\f\+\.go$'
call go#cmd#Build(0)
endif
endfunction
augroup go
autocmd!
autocmd FileType go nmap <silent> <leader>b :<C-u>call <SID>build_go_files()<CR>
autocmd FileType go nmap <silent> <leader>t <Plug>(go-test)
autocmd FileType go nmap <silent> <leader>r <Plug>(go-run)
autocmd FileType go nmap <silent> <leader>e <Plug>(go-install)
" TEST FOR python TODO
" autocmd FileType py nmap <silent> <leader>r <!python %>
" we want to tell the syntastic module when to run
" we want to see code highlighting and checks when we open a file
" but we don't care so much that it reruns when we close the file
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" we also want to get rid of accidental trailing whitespace on save
autocmd BufWritePre * :%s/\s\+$//e
" tell vim to allow you to copy between files, remember your cursor
" position and other little nice things like that
set viminfo='100,\"2500,:200,%,n~/.viminfo
" ==================== Fugitive ====================
vnoremap <leader>gb :Gblame<CR>
nnoremap <leader>gb :Gblame<CR>
" ==================== NerdTree ====================
" For toggling
noremap <Leader>n :NERDTreeToggle<cr>
noremap <Leader>f :NERDTreeFind<cr>
let NERDTreeShowHidden=1
" ==================== ag ====================
let g:ackprg = 'ag --vimgrep --smart-case'
" ==================== NerdCommenter ====================
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
let g:NERDCustomDelimiters = { 'forth': { 'left': '//','right': '' } }
" Quick Run
" Quick run via <F5>
nnoremap <Leader>r :call <SID>compile_and_run()<CR>
function! s:compile_and_run()
exec 'w'
if &filetype == 'c'
exec "AsyncRun! gcc % -o %<; time ./%<"
elseif &filetype == 'cpp'
exec "AsyncRun! g++ -std=c++11 % -o %<; time ./%<"
elseif &filetype == 'hs' || &filetype == 'haskell'
exec "AsyncRun! ghc -o %< %; time ./%<"
elseif &filetype == 'java'
exec "AsyncRun! javac %; time java %<"
elseif &filetype == 'sh'
exec "AsyncRun! time bash %"
elseif &filetype == 'python'
exec "AsyncRun! time python3 %"
elseif &filetype == 'ocaml' || &filetype == 'merlin'
exec "AsyncRun! ocaml %"
elseif &filetype == 'javascript'
exec "AsyncRun! rhino %"
elseif &filetype == 'tex'
exec "AsyncRun! pdflatex %"
elseif &filetype == 'fsharp' || &filetype == 'fsx' || &filetype == 'fs'
exec "AsyncRun! dotnet fsi %"
elseif &filetype == 'rust'
exec "AsyncRun! rustc % -A warnings; time ./%<"
elseif &filetype == 'forth'
exec "AsyncRun! dotnet run %"
endif
endfunction
" run rustfmt on save globally for rust files
let g:rustfmt_autosave = 1
" asyncrun now has an option for opening quickfix automatically
let g:asyncrun_open = 15
" Markdown additional options for syntax formatting/preview
let g:vim_markdown_math = 1 "Allows use of LaTeX
" Set relative line numbers in insert mode and absolute line
" Numbers in normal mode
:set number relativenumber
:augroup numbertoggle
: autocmd!
: autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
: autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
:augroup END
" for google-java-format
let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
execute "set rtp+=" . g:opamshare . "/merlin/vim"
" ## added by OPAM user-setup for vim / base ## 93ee63e278bdfc07d1139a748ed3fff2 ## you can edit, but keep this line
let s:opam_share_dir = system("opam config var share")
let s:opam_share_dir = substitute(s:opam_share_dir, '[\r\n]*$', '', '')
let s:opam_configuration = {}
function! OpamConfOcpIndent()
execute "set rtp^=" . s:opam_share_dir . "/ocp-indent/vim"
endfunction
let s:opam_configuration['ocp-indent'] = function('OpamConfOcpIndent')
function! OpamConfOcpIndex()
execute "set rtp+=" . s:opam_share_dir . "/ocp-index/vim"
endfunction
let s:opam_configuration['ocp-index'] = function('OpamConfOcpIndex')
function! OpamConfMerlin()
let l:dir = s:opam_share_dir . "/merlin/vim"
execute "set rtp+=" . l:dir
endfunction
let s:opam_configuration['merlin'] = function('OpamConfMerlin')
let s:opam_packages = ["ocp-indent", "ocp-index", "merlin"]
let s:opam_check_cmdline = ["opam list --installed --short --safe --color=never"] + s:opam_packages
let s:opam_available_tools = split(system(join(s:opam_check_cmdline)))
for tool in s:opam_packages
" Respect package order (merlin should be after ocp-index)
if count(s:opam_available_tools, tool) > 0
call s:opam_configuration[tool]()
endif
endfor
" ## end of OPAM user-setup addition for vim / base ## keep this line
" tabstop for reason and ocaml files
set noexpandtab
set tabstop=4
set softtabstop=0
set shiftwidth=4
autocmd FileType html setlocal shiftwidth=2 tabstop=2
autocmd FileType yaml setlocal shiftwidth=2 tabstop=2
autocmd FileType typescript setlocal shiftwidth=2 tabstop=2
autocmd FileType css setlocal shiftwidth=2 tabstop=2
autocmd FileType forth setlocal shiftwidth=2 tabstop=4 expandtab
" py format setup (link: https://github.com/Chiel92/vim-autoformat)
" /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
let g:format_black_py = '"python3.9 -m yapf "'
let g:formatters_py = ['format_black_py']
let g:format_eslint_ts = '"eslint --fix"'
let g:formatters_ts = ['format_eslint_ts']
au BufWrite *.py :silent Autoformat
au BufWrite *.ts :silent Autoformat
nmap <Leader>f :silent Autoformat <CR>
" for ctags
nmap <Leader>1 :TagbarToggle<CR>
" Disable linting for python and dart files
let g:ale_pattern_options = {'*.py': {'ale_enabled': 1}}
let g:ale_pattern_options = {'*.dart': {'ale_enabled': 0}}
" On cursor short dict lookup
function Sdict()
echo system("dict " . expand("<cword>") . " | head -n 30")
return 1
endfunction
nmap <Leader>* :call Sdict() <CR>
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
" let g:syntastic_always_populate_loc_list = 1
" let g:syntastic_auto_loc_list = 1
" let g:syntastic_check_on_open = 1
" let g:syntastic_check_on_wq = 0
let g:dart_format_on_save = 1
let dart_html_in_string=v:true
" typescript formatter with prettier
let g:prettier#autoformat = 1
let g:prettier#autoformat_require_pragma = 0
let g:prettier#exec_cmd_async = 1
au BufWrite *.jsx :silent PrettierAsync
" au BufWrite *.tsx :silent PrettierAsync
autocmd FileType typescript setlocal formatprg=prettier\ --parser\ typescript