-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
687 lines (531 loc) · 16.7 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
" Vim configuration file
" Author: Jonathan Filip
" Setup: {{{1 ================================================================
set encoding=utf-8
" Set location so we can set variables accordingly
let g:os = ""
if has("win32") || has("win64")
let g:os="win"
elseif has("win32unix")
let g:os = "cygwin"
elseif has("unix")
let g:os = "linux"
endif
" Settings: {{{1 =============================================================
set browsedir=buffer
set hidden
set history=1000
set mouse=a
set shortmess=filmnrxoOtTI
set backspace=indent,eol,start
set confirm
set foldmethod=manual
set formatoptions=tcrqnlj
set nojoinspaces
set nowrap
set nrformats-=octal
set scrollopt=jump,ver,hor
set sidescroll=10
set splitbelow
set splitright
set virtualedit=block
set whichwrap+=<,>,h,l
set linebreak
if exists("+breakindent")
set breakindent
set showbreak=\ \ \\_
endif
" GUI/terminal and colors
" let g:airline_theme = "lucius"
if !has("gui_running")
if &term == "screen-256color"
set term=xterm-256color
endif
if has("termguicolors") && $COLORTERM ==? "truecolor"
set termguicolors
endif
set ttymouse=sgr
endif
" Use system clipboard
if has("clipboard")
if has("unnamedplus")
set clipboard=unnamedplus,unnamed
else
set clipboard=unnamed
endif
else
set clipboard=
endif
" Grep
if g:os == "linux"
if executable('rg')
set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case
elseif executable('ag')
set grepprg=ag\ --nogroup\ --nocolor\ --vimgrep
elseif executable('ack')
set grepprg=ack\ -s\ --with-filename\ --nocolor\ --nogroup\ --column
endif
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
if g:os != "win"
set shellslash
endif
syntax on
set path=.,**
set tags=./tags;/.
if version >= 704 && has("patch-7.4-399")
set cryptmethod=blowfish2
elseif version >= 703
set cryptmethod=blowfish
endif
if version >= 801 && has("patch-8.1-360")
set diffopt+=indent-heuristic
set diffopt+=algorithm:patience
endif
" UI Settings: {{{2 ----------------------------------------------------------
set cmdheight=1
set colorcolumn=+1
set cursorline
set display+=lastline
" set fillchars=
set guioptions=egc
set laststatus=2
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
set noequalalways
set noerrorbells
set novisualbell
set ruler
set showcmd
set showmatch
set showmode
set synmaxcol=1000
set winminheight=0
set winminwidth=0
if has("gui_running")
set title
if g:os == "osx"
set lines=80 columns=200 fuoptions=maxvert,maxhorz
else
set lines=60 columns=210
endif
if g:os == "win"
set guifont=Cascadia_Mono_PL:h9
elseif has("gui_macvim")
set guifont=Cascadia_Mono_PL:h13
set antialias
endif
else
set guioptions+=aA
endif
" Search Settings: {{{2 ------------------------------------------------------
set ignorecase
set incsearch
set nohlsearch
set smartcase
" Indentation Settings: {{{2 -------------------------------------------------
set autoindent
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
set smarttab
set shiftround
" Completion Settings: {{{2 --------------------------------------------------
set complete=.,w,b,u
set completeopt=longest,menu
set wildignorecase
set wildmenu
set wildmode=longest:full,full
" set wildmode=list:longest,full
set pumheight=16
set wildignore+=*.pyc,*.pyd,*.pyo " python files
set wildignore+=*.bmp,*.gif,*.ico,*.png,*.jpg,*.jpeg " images
set wildignore+=*.csproj,*.pdb,*.resx,*.sln,*.suo " visual studio
set wildignore+=*.doc,*.docx,*.pdf,*.xls,*.xlsx " documents
set wildignore+=*.dll,*.exe,*.lib,*.map,*.o,*.obj,*.so " binaries
set wildignore+=*.h5,*.gz " compressed files
set wildignore+=*.bak,*~,tmp " misc files
set wildignore+=.svn\*,.git\* " scm
set wildignore+=cscope.out,tags " vim
" File Settings: {{{2 --------------------------------------------------------
filetype plugin indent on
set noautoread
set fileformats=unix,dos
set nobackup
set nowritebackup
set noswapfile
" Mappings: {{{1 =============================================================
let g:mapleader = "\<Space>"
let g:maplocalleader = "\<Space>"
" Indenting in visual mode
xnoremap <silent> <tab> >gv
xnoremap <silent> <s-tab> <gv
xnoremap <silent> > >gv
xnoremap <silent> < <gv
" Backspace
xnoremap <BS> d
if g:os == "osx"
inoremap <A-BS> <C-w>
elseif g:os == "win"
inoremap <C-BS> <C-w>
endif
" Format
noremap <Leader>gq gqap
" Buffer contorls
nnoremap <silent> <leader>n :bnext<CR>
nnoremap <silent> <leader>p :bprev<CR>
" Refresh
nnoremap <silent> <F5> :e<CR>
" Diff commands
nnoremap <silent> <leader>dt :diffthis<CR>
nnoremap <silent> <leader>do :diffoff!<CR>
" Window control
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" Resize windows
nnoremap <Up> 10<C-W>+
nnoremap <Down> 10<C-W>-
nnoremap <Left> 10<C-W><
nnoremap <Right> 10<C-W>>
" Splitting
nnoremap <leader>sp :split<CR>
nnoremap <leader>vs :vsplit<CR>
" Make x not yank to register
noremap x "_x
" CTRL-A is Select all, etc
if g:os != "osx"
noremap <C-A> ggVG
inoremap <C-A> <C-O>gg<C-O>gH<C-O>G
cnoremap <C-A> <C-C>gggH<C-O>G
onoremap <C-A> <C-C>gggH<C-O>G
snoremap <C-A> <C-C>gggH<C-O>G
xnoremap <C-A> <C-C>ggVG
endif
" Don't bring up help on F1
noremap <F1> <ESC>
inoremap <F1> <ESC>
" Disable middle mouse button pasting
noremap <MiddleMouse> <Nop>
inoremap <MiddleMouse> <Nop>
noremap <2-MiddleMouse> <Nop>
inoremap <2-MiddleMouse> <Nop>
noremap <3-MiddleMouse> <Nop>
inoremap <3-MiddleMouse> <Nop>
noremap <4-MiddleMouse> <Nop>
inoremap <4-MiddleMouse> <Nop>
" Get rid of Ex mode
nnoremap <S-Q> <Q>
" Preview tag on Enter
nnoremap <silent> <leader><CR> :ptjump <C-R>=expand("<cword>")<CR><CR>
" Highlight text from last Insert mode
nnoremap <silent> gV `[v`]
" Functions: {{{1 ============================================================
function! s:TabComplete(mode)
let cmd = a:mode == "P" ? "\<C-P>" : "\<C-N>"
if pumvisible()
return cmd
endif
let pos = getpos('.')
" Only match letters, numbers, slashes, and dots.
let pattern = "[A-Za-z0-9/.]*$"
let substr = matchstr(strpart(getline(pos[1]), 0, pos[2] - 1), pattern)
if empty(substr)
return (a:mode == "P") ? "\<C-d>" : "\<Tab>"
endif
let file_path = '\/'
let file_pattern = match(substr, file_path) != -1
if file_pattern
return "\<C-x>\<C-f>"
endif
return cmd
endfunction
" Only needed to prevent setting in vsvim
if v:version > 700
inoremap <silent> <Tab> <C-R>=<SID>TabComplete("N")<CR>
inoremap <silent> <S-Tab> <C-R>=<SID>TabComplete("P")<CR>
endif
" Commands: {{{1 =============================================================
" Strip extra whitespace
command! Strip %s/\s\+$//
" Change directory to current buffer
command! CD :lcd %:p:h
" Save command typos
command! Q q
command! QA qa
command! Qa qa
command! W w
command! Wq wq
command! WQ wq
" Insert date
command! Date put! =strftime('%Y-%m-%d')
" Plugins: {{{1 ==============================================================
if g:os == "win"
call plug#begin('~/vimfiles/bundle')
else
call plug#begin('~/.vim/bundle')
endif
Plug 'https://github.com/ctrlpvim/ctrlp.vim'
Plug 'https://github.com/othree/xml.vim'
Plug 'https://github.com/tomtom/tcomment_vim'
Plug 'https://github.com/vim-airline/vim-airline'
Plug 'https://github.com/vim-pandoc/vim-pandoc'
Plug 'https://github.com/vim-pandoc/vim-pandoc-syntax'
Plug 'https://github.com/tpope/vim-fugitive'
Plug 'https://github.com/chaoren/vim-wordmotion'
Plug 'https://github.com/sheerun/vim-polyglot'
Plug 'https://github.com/w0rp/ale'
Plug 'https://github.com/gruvbox-community/gruvbox'
if g:os != "win"
Plug 'https://github.com/will133/vim-dirdiff'
Plug 'https://github.com/preservim/tagbar'
endif
if v:version > 704 || v:version == 704 && has("patch1826")
Plug 'airblade/vim-gitgutter'
endif
call plug#end()
" Airline: {{{2 --------------------------------------------------------------
" let g:airline_left_sep = ''
" let g:airline_right_sep = ''
" let g:airline_inactive_collapse = 1
let g:airline_powerline_fonts = 1
" let g:airline_symbols_ascii = 1
" let g:airline_extensions = ['ctrlp']
" let g:airline#extensions#default#layout = [
" \ [ 'a', 'c' ],
" \ [ 'x', 'y', 'z', 'error', 'warning' ]
" \ ]
let g:airline#extensions#wordcount#enabled = 0
let g:airline#extensions#whitespace#enabled = 0
if g:os != "linux"
let g:airline_extensions = []
endif
" ALE: {{{2 ------------------------------------------------------------------
let g:ale_linters = {
\ "python": ["flake8"],
\ "cpp": [],
\ }
let g:ale_lint_on_enter = 1
let g:ale_set_signs = 0
let g:ale_python_flake8_options = "--ignore=E501"
let g:ale_set_balloons = 0
let g:ale_fixers = {
\ "python": ["black", "isort"]
\}
let g:ale_python_black_options = "-l 100"
let g:ale_python_isort_options = "-l 100"
" Ctags: {{{2 ----------------------------------------------------------------
let g:ctags_bin = "ctags"
" CtrlP: {{{2 ----------------------------------------------------------------
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_custom_ignore = {
\ 'dir': 'tests$',
\ 'file': '',
\ }
let g:ctrlp_lazy_update = 0
let g:ctrlp_match_window='position:bottom,order:btt,min:1,max:10,results:100'
let g:ctrlp_show_hidden = 0
let g:ctrlp_switch_buffer = 0
let g:ctrlp_working_path_mode = 0
if g:os == "linux"
if executable('rg')
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
elseif executable('ag')
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
if len(&wildignore > 0)
let g:ctrlp_user_command = g:ctrlp_user_command . ' --ignore=' . &wildignore
endif
let g:ctrlp_use_caching = 0
endif
elseif g:os == "win"
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 0
endif
nnoremap <silent> <leader>ff :CtrlP<CR>
nnoremap <silent> <leader>fb :CtrlPBuffer<CR>
nnoremap <silent> <leader>fr :CtrlPMRU<CR>
nnoremap <silent> <leader>ft :CtrlPBufTag<CR>
" Dbext: {{{2 ----------------------------------------------------------------
let g:dbext_default_prompt_for_parameters = 0
let g:dbext_default_display_cmd_line = 1
let g:dbext_default_SQLITE_bin = "sqlite3"
let g:dbext_default_history_file = "$HOME/.dbext_sql_history.txt"
" Git Gutter: {{{2 -----------------------------------------------------------
let g:gitgutter_override_sign_column_highlight = 0
" Myfuncs: {{{2 --------------------------------------------------------------
let g:projects = {}
let g:databases = {}
" Pandoc: {{{2 ---------------------------------------------------------------
let g:pandoc#modules#enabled = [
\"command",
\"formatting",
\"metadata",
\"keyboard" ,
\"toc",
\"completion",
\]
" let g:pandoc#formatting#mode = "ha"
let g:pandoc#formatting#textwidth = "79"
let g:pandoc#keyboard#enabled_submodules = [
\"lists",
\"references",
\"styles",
\"sections",
\"links"]
let g:pandoc#spell#enabled = 1
let g:pandoc#syntax#codeblocks#embeds#langs = [
\"python",
\"cpp",
\"c",
\"cs",
\"sql",
\"xml",
\]
let g:pandoc#formatting#extra_equalprg = ""
augroup pandoc
autocmd!
autocmd BufEnter *.md :syntax spell toplevel
autocmd BufEnter *.md :set spell
augroup end
" Python: {{{2 ---------------------------------------------------------------
let g:python_highlight_all = 1
let g:pyindent_open_paren = "&sw"
let g:pyindent_nested_paren = "&sw"
let g:pyindent_continue = "&sw"
augroup python
autocmd!
autocmd BufEnter *.py :syntax sync fromstart " helps with ''' comments
augroup end
" WordMotion: {{{2 -----------------------------------------------------------
let g:wordmotion_prefix='<leader>'
" Polyglot: {{{2 -----------------------------------------------------------
let g:python_pep8_indent_hang_closing = 0
" Autocommands: {{{1 =========================================================
" Only show cursor line in current buffer in normal mode
augroup cursor_line
autocmd!
autocmd InsertEnter * set nocursorline
autocmd InsertLeave * set cursorline
autocmd WinEnter * set cursorline colorcolumn=+1
autocmd WinLeave * set nocursorline colorcolumn=
augroup end
" Close the preview window automatically
augroup preview_window
autocmd!
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
augroup end
" Set xaml to be like xml
augroup xaml
autocmd!
autocmd BufNewFile *.xaml setfiletype xml
autocmd BufRead *.xaml setfiletype xml
augroup end
augroup cpp
autocmd!
autocmd BufNewFile *.c setfiletype cpp
autocmd BufRead *.c setfiletype cpp
autocmd BufNewFile *.C setfiletype cpp
autocmd BufRead *.C setfiletype cpp
autocmd BufNewFile *.H setfiletype cpp
autocmd BufRead *.H setfiletype cpp
augroup end
" Miscellaneous: {{{1 ========================================================
" Load matchit.vim, but only if the user hasn't installed a newer version.
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# ''
runtime! macros/matchit.vim
endif
" Colorscheme: {{{1 ==========================================================
" colorscheme lucius
" colorscheme lucius
let g:gruvbox_vert_split = "bg1"
let g:gruvbox_contrast_dark = "medium"
let g:gruvbox_italic = 0
let g:gruvbox_bold = 0
set background=dark
colorscheme gruvbox
hi! link Statement GruvboxBlue
hi! link Conditional GruvboxBlue
hi! link Repeat GruvboxBlue
hi! link Exception GruvboxBlue
hi! link Keyword GruvboxBlue
hi! link pythonOperator GruvboxBlue
hi! link pythonException GruvboxBlue
hi! link pythonConditional GruvboxBlue
hi! link pythonRepeat GruvboxBlue
" if $TERM_PROGRAM ==? "Apple_Terminal"
" let s:mode = system("defaults read -g AppleInterfaceStyle")
" if s:mode =~ '^Dark'
" set background=dark
" else
" set background=light
" endif
" colorscheme gruvbox
" else
" colorscheme gruvbox
" endif
function! HighlightCS(group, fg, bg, opt)
let l:str_fg = a:fg
if type(a:fg) == v:t_number
let l:str_fg = "#" . printf("%06x", a:fg)
endif
let l:str_bg = a:bg
if type(a:bg) == v:t_number
let l:str_bg = "#" . printf("%06x", a:bg)
endif
let l:cmd = "hi " . a:group . " guifg=" . l:str_fg . " guibg=" . l:str_bg
if a:opt != ""
let l:cmd = l:cmd . " gui=" . a:opt . " cterm=" . a:opt
endif
exec l:cmd
endfunction
function! AdjustCS(hex_code, factor)
if a:hex_code == "NONE"
return a:hex_code
endif
let l:num = str2nr(strpart(a:hex_code, 1), 16)
let l:red = min([0xff, float2nr(round(l:num % 0x1000000 / 0x10000 * (1 + a:factor)))])
let l:green = min([0xff, float2nr(round(l:num % 0x10000 / 0x100 * (1 + a:factor)))])
let l:blue = min([0xff, float2nr(round(l:num % 0x100 * (1 + a:factor)))])
return 0x10000 * l:red + 0x100 * l:green + l:blue
endfunction
function! AdjustRGBCS(hex_code, rfactor, gfactor, bfactor)
let l:red = min([0xff, float2nr(round(a:hex_code % 0x1000000 / 0x10000 * (1 + a:rfactor)))])
let l:green = min([0xff, float2nr(round(a:hex_code % 0x10000 / 0x100 * (1 + a:gfactor)))])
let l:blue = min([0xff, float2nr(round(a:hex_code % 0x100 * (1 + a:bfactor)))])
return 0x10000 * l:red + 0x100 * l:green + l:blue
endfunction
function! GetFG(name)
exec "let l:gfg = synIDattr(synIDtrans(hlID('" . a:name .
\ "')), 'fg', 'gui')"
let l:gfg = l:gfg == "" ? "NONE" : l:gfg
return l:gfg
endfunction
function! GetBG(name)
exec "let l:gfg = synIDattr(synIDtrans(hlID('" . a:name .
\ "')), 'bg', 'gui')"
let l:gbg = l:gbg == "" ? "NONE" : l:gbg
return l:gbg
endfunction
call HighlightCS("DiffAdd", "NONE", AdjustCS(GetFG("GruvboxAqua"), -0.70), "none")
call HighlightCS("DiffDelete", AdjustCS(GetFG("DiffDelete"), -0.55), AdjustCS(GetFG("DiffDelete"), -0.65), "none")
call HighlightCS("DiffChange", "NONE", AdjustCS(GetFG("GruvboxYellow"), -0.70), "none")
call HighlightCS("DiffText", "NONE", AdjustCS(GetFG("GruvboxOrange"), -0.50), "none")
" let s:mode = systemlist("defaults read -g AppleInterfaceStyle")[0]
" if s:mode ==? "dark"
" set background=dark
" colorscheme iceberg
" else
" set background=light
" colorscheme iceberg
" endif
" else
" LuciusWhite
" endif
" Local Settings: {{{1 =======================================================
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif
" vim: nofoldenable foldmethod=marker