-
Notifications
You must be signed in to change notification settings - Fork 16
/
.vimrc
624 lines (521 loc) · 16 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
" Preamble {{{
" ---------------------------------------------------------------------------
set nocompatible " be iMproved
" Automatically install vim-plug if it isn't installed
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" }}}
" Plugins {{{
" ---------------------------------------------------------------------------
call plug#begin('~/.vim/plugged')
" Programming
Plug 'vim-scripts/matchit.zip'
if v:version >= 703
Plug 'majutsushi/tagbar', { 'on': 'TagbarToggle' }
endif
Plug 'tpope/vim-commentary', { 'on': ['<Plug>Commentary', '<Plug>CommentaryLine'] }
Plug 'w0rp/ale'
" Snippets
Plug 'SirVer/ultisnips' ", { 'on': [] }
Plug 'honza/vim-snippets' ", { 'on': [] }
" Git
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'rhysd/git-messenger.vim'
" Plug 'airblade/vim-gitgutter'
" Ruby
Plug 'tpope/vim-rails', { 'for': 'ruby' }
" Additional language files
Plug 'sheerun/vim-polyglot'
" Utility
Plug 'wellle/targets.vim'
Plug 'vim-scripts/LargeFile'
Plug 'vim-scripts/file-line'
Plug 'ConradIrwin/vim-bracketed-paste'
Plug 'ervandew/supertab' ", { 'on': [] }
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-sleuth' ", { 'on': [] }
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-obsession'
Plug 'godlygeek/tabular', { 'on': 'Tabularize' }
Plug 'eiginn/netrw',
Plug 'tpope/vim-vinegar' ", { 'on': 'Explore' }
Plug 'vim-scripts/ZoomWin'
Plug 'mileszs/ack.vim'
Plug 'mbbill/undotree', { 'on': 'UndotreeToggle' }
Plug 'whiteinge/diffconflicts'
Plug 'google/vim-searchindex'
Plug 'thcipriani/mediummode', { 'on': 'MediumModeToggle' }
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'Lokaltog/vim-easymotion', { 'on': ['<Plug>(easymotion-s2)', '<Plug>(easymotion-j)', '<Plug>(easymotion-k)'] }
Plug 'rhysd/clever-f.vim'
Plug 'christoomey/vim-tmux-navigator'
Plug 'terryma/vim-expand-region', { 'on': ['<Plug>(expand_region_expand)', '<Plug>(expand_region_shrink)'] }
Plug 'AndrewRadev/splitjoin.vim'
Plug 'bling/vim-airline'
call plug#end()
" }}}
" General {{{
" ---------------------------------------------------------------------------
let mapleader = ","
let g:mapleader = ","
set encoding=utf-8
set history=50 " keep 50 lines of command line history
set hidden
set confirm
set nobackup
set nowritebackup
set noswapfile
set undofile
set autoread
set sessionoptions="blank,buffers,curdir,folds,help,tabpages,winsize"
set nomodeline " disable mode lines (security measure)
set smarttab
set shiftround
set number
set relativenumber
set cursorline
" Match and search
set ignorecase " Do case insensitive matching
set smartcase
set gdefault
set incsearch " do incremental searching
set showmatch " Show matching brackets.
" Use sane regexes.
" nnoremap / /\v
" vnoremap / /\v
if has("nvim")
set inccommand=nosplit
endif
" Spell
if has("spell")
" set spelllang=fr
set spelllang=en_us
nnoremap <leader>ss :set spell!<CR>
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
if has("nvim")
" Make escape work in the Neovim terminal
tnoremap <Esc> <C-\><C-n>
" Make navigation into and out of Neovim terminal splits nicer
tnoremap <C-h> <C-\><C-N><C-w>h
tnoremap <C-j> <C-\><C-N><C-w>j
tnoremap <C-k> <C-\><C-N><C-w>k
tnoremap <C-l> <C-\><C-N><C-w>l
" Relative numbers when in normal mode
autocmd TermOpen * setlocal conceallevel=0 colorcolumn=0 relativenumber
" Start terminal in insert mode
autocmd TermOpen term://* startinsert
endif
" Wildmenu completion {{{
set wildmenu
set wildmode=list:longest,list:full
set wildignore+=.hg,.git,.svn " Version control
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.pyc " Python byte code
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.DS_Store? " OSX bullshit
" }}}
" }}}
" UI {{{
" ---------------------------------------------------------------------------
set title
set scrolloff=3
set sidescroll=1
set sidescrolloff=10
set listchars+=precedes:❮,extends:❯
set showbreak=↪
set ruler
set noshowmode
set showcmd
set novisualbell
set backspace=indent,eol,start
set laststatus=2
set virtualedit+=block
set display+=lastline
set ttimeoutlen=20
" }}}
" Text Formatting {{{
" ---------------------------------------------------------------------------
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Insert mode plugins {{{
" augroup insert_mode_plugins
" autocmd!
" autocmd InsertEnter * call plug#load('supertab',
" \ 'ultisnips', 'vim-snippets', 'vim-endwise',
" \ 'vim-repeat', 'vim-sleuth')
" " \ 'vim-sleuth', 'supertab', 'syntastic')
" augroup END
" }}}
" text files settings {{{
augroup filetype_text
autocmd!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
augroup END
" }}}
" ruby files settings {{{
augroup filetype_ruby
autocmd!
" Use # to create string interpolation with vim-surround
autocmd FileType ruby let b:surround_35 = "#{\r}"
" Delete trailing spaces from ruby files
autocmd BufWritePre *.rb :%s/\s\+$//e
if has("balloon_eval")
" Annoying plugins keep turning ballooneval on
autocmd BufEnter *.rb setlocal noballooneval
endif
augroup END
" }}}
" git commit messages {{{
augroup filetype_gitcommit
autocmd!
" Show Git diff in window split when commiting
autocmd FileType gitcommit DiffGitCached | wincmd L | wincmd p
" Spellcheck commit messages
autocmd FileType gitcommit setlocal spell!
augroup END
" }}}
" command window {{{
augroup command_window
autocmd!
" Have <esc> leave cmdline-window
autocmd CmdwinEnter * nnoremap <buffer> <ESC> :q<CR>
augroup END
" }}}
" persistent undo {{{
augroup undo
autocmd!
autocmd BufWritePre /tmp/* setlocal noundofile
augroup END
" }}}
" Utilities {{{
augroup utilities
autocmd!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Resize splits when the window is resized
autocmd VimResized * exe "normal! \<c-w>="
" When vimrc is edited, automatically reload it
autocmd bufwritepost .vimrc source %
augroup END
" }}}
" Netrw mappings {{{
augroup netrw_mappings
autocmd!
autocmd filetype netrw call Netrw_mappings()
augroup END
function! Netrw_mappings()
map <buffer> h -
map <buffer> l <CR>
endfunction
" }}}
else
set autoindent " always set autoindenting on
endif " has("autocmd")
set formatoptions+=n1rj
set expandtab
" }}}
" Status Line {{{
" ---------------------------------------------------------------------------
set statusline=%#warningmsg#
set statusline+=%*
set statusline+=%{fugitive#statusline()}
set statusline+=\ %<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
" set statusline+=%{ruby_debugger#statusline()}
" }}}
" Mappings {{{
" ---------------------------------------------------------------------------
" Shortcuts to often edited files
nnoremap <leader>ev :vsplit $HOME/.vimrc<cr>
nnoremap <leader>ez :vsplit $HOME/.zshrc<cr>
nnoremap <leader>et :vsplit $HOME/.tmux.conf<cr>
nnoremap <leader>es :vsplit $HOME/.ssh/config<cr>
" Toggle settings
nnoremap <leader>sn :set number!<cr>
nnoremap <leader>sr :set relativenumber!<cr>
nnoremap <leader>sw :set wrap!<cr>
nnoremap <silent> <leader>sl :call ToggleCursorline()<cr>
nnoremap <leader>sh :MediumModeToggle<cr>
nnoremap <leader>sp :set paste!<CR>
function! ToggleCursorline()
let g:cursorline_active = !&cursorline
set cursorline!
endfunction
let g:cursorline_active = &cursorline
" Highlight cursorline ONLY in the active window
augroup cursor_line
autocmd!
autocmd WinEnter * if g:cursorline_active | setlocal cursorline | endif
autocmd WinLeave * if g:cursorline_active | setlocal nocursorline | endif
augroup END
" Easy copy/paste from system clipboard
vmap <Leader>y "+y
vmap <Leader>d "+d
nmap <Leader>p "+p
nmap <Leader>P "+P
vmap <Leader>p "+p
vmap <Leader>P "+P
" Surround with quotes
nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
nnoremap <leader>' viw<esc>a'<esc>hbi'<esc>lel
" Tabularize
nnoremap <leader>a= :Tabularize /=<cr>
vnoremap <leader>a= :Tabularize /=<cr>
nnoremap <leader>a: :Tabularize /:\zs<cr>
vnoremap <leader>a: :Tabularize /:\zs<cr>
" Easier start/end of line
noremap H ^
noremap L $
" <Ctrl>-d deletes the line
inoremap <c-d> <esc>ddi
" <Ctrl>-u make the current word uppercase
inoremap <c-u> <esc>viwUi
" Center screen when scrolling search results
" nnoremap n nzz
" nnoremap N Nzz
" Move between splits
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Make something useful from these arrow keys
nmap <Left> <<
nmap <Right> >>
vmap <Left> <gv
vmap <Right> >gv
nmap <Up> [m
nmap <Down> ]m
" Map ESC
inoremap jk <esc>
inoremap kj <esc>
" inoremap <esc> <nop>
" Expand current file path
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" Stop highlight search
nnoremap <CR> :noh<CR>
map <SPACE> <Plug>(easymotion-s2)
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
" Don't use Ex mode, use Q for formatting
noremap Q gq
" Select pasted text
nnoremap <leader>v V`]
" Quick yanking to the end of the line
nmap Y y$
" Just because I'm used to it
nnoremap <c-p> :Files<CR>
" Ack the word under the cursor
nnoremap <leader>a :Ack! <cword><CR>
" Easy completion of method name in insert mode
inoremap <c-x><c-]> <c-]>
" Use . for visual selection
vnoremap . :norm.<CR>
function! s:try(cmd, default)
if exists(':' . a:cmd) && !v:count
let tick = b:changedtick
execute a:cmd
if tick == b:changedtick
execute join(['normal!', a:default])
endif
else
execute join(['normal! ', v:count, a:default], '')
endif
endfunction
nnoremap <silent> J :<C-u>call <SID>try('SplitjoinJoin', 'J')<CR>
nnoremap <silent> S :<C-u>call <SID>try('SplitjoinSplit', "r\015")<CR>
nmap <silent> gd <Plug>(ale_go_to_definition)
" }}}
" Function Keys {{{
" ---------------------------------------------------------------------------
" <F1> Escape
inoremap <F1> <ESC>
noremap <F1> <ESC>
" <F2> File explorer
noremap <F2> :Explore<CR>
" <F3> Buffer explorer
noremap <F3> :Buffers<CR>
" <F4> Tagbar
noremap <F4> :TagbarToggle<CR>
" <F5> Reload file
noremap <F5> :e!<CR>
" <F7> Toggle Undo tree
noremap <F7> :UndotreeToggle<CR>
" <F8> Comment
nmap <F8> <Plug>CommentaryLine<ESC>j
xmap <F8> <Plug>Commentary
" <F9> Remove all trailing spaces
noremap <F9> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>
" <F12> Compile using makefile
noremap <F12> :make<CR>
" }}}
" Plugins Config {{{
" ---------------------------------------------------------------------------
" Ruby
" let g:rubycomplete_buffer_loading=1
let ruby_space_errors=1
let g:ale_lint_on_text_changed='never'
let g:ale_sign_error='✖'
let g:ale_sign_warning='⚠'
let g:ale_sign_info='ℹ'
let g:ale_echo_msg_error_str='E'
let g:ale_echo_msg_warning_str='W'
let g:ale_echo_msg_info_str='I'
let g:ale_echo_msg_format='[%linter%] %s [%severity%]'
let g:ale_fix_on_save=1
let g:ale_linters = {
\ 'go': ['gopls'],
\}
let g:ale_fixers = {
\ 'go': ['gofmt'],
\}
let g:ale_completion_symbols = {
\ 'text': 'text',
\ 'method': '',
\ 'function': '',
\ 'constructor': '',
\ 'field': '',
\ 'variable': '',
\ 'class': '',
\ 'interface': '',
\ 'module': '',
\ 'property': '',
\ 'unit': 'unit',
\ 'value': 'val',
\ 'enum': '',
\ 'keyword': 'keyword',
\ 'snippet': 'snippet',
\ 'color': 'color',
\ 'file': '',
\ 'reference': 'ref',
\ 'folder': '🗂',
\ 'enum member': '',
\ 'constant': '',
\ 'struct': 'struct',
\ 'event': 'event',
\ 'operator': '',
\ 'type_parameter': 'type param',
\ '<default>': 'v'
\}
set omnifunc=ale#completion#OmniFunc
" SuperTab
let g:SuperTabDefaultCompletionType="context"
" let g:SuperTabContextDefaultCompletionType="<c-x><c-o>"
" let g:SuperTabCrMapping=0
" UltiSnips
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsEditSplit="vertical"
" SplitJoin
let g:splitjoin_align=1
" Put tagbar on the left
let g:tagbar_left=1
" Ack
let g:ackprg='ag --nogroup --nocolor --column'
let g:ack_wildignore = 0
let g:ackhighlight=1
" EasyMotion
let g:EasyMotion_smartcase = 1
let g:EasyMotion_use_smartsign_jp = 1
" Clever-f
let g:clever_f_smart_case=1
let g:clever_f_timeout_ms=10000
let g:clever_f_show_prompt=1
let g:clever_f_mark_cursor=1
let g:clever_f_chars_match_any_signs=';:'
let g:clever_f_fix_key_direction=1
" Medium mode
let g:mediummode_enabled = 0
let g:mediummode_allowed_motions = 5
" Airline
let g:airline#extensions#tagbar#enabled=0
let g:airline#extensions#hunks#enabled=0
let g:airline#extensions#ale#enabled=1
let g:airline_theme='twilight'
" Mustache
let g:mustache_abbreviations = 1
" Undotree
let g:undotree_WindowLayout = 2
" }}}
" GUI {{{
" ---------------------------------------------------------------------------
" Use a line-drawing char for pretty vertical splits.
set fillchars+=vert:│
colorscheme twilight
if !has('nvim')
set ttymouse=sgr
endif
set mouse=a
set t_Co=256
" }}}
" Misc {{{
" ---------------------------------------------------------------------------
" Ensure the temp dirs exist
if !isdirectory($HOME . "/.vim/.tmp")
call system("mkdir -p ~/.vim/.tmp/backup")
call system("mkdir -p ~/.vim/.tmp/undo")
call system("mkdir -p ~/.vim/.tmp/yankring")
call system("mkdir -p ~/.vim/.tmp/ctrlp")
call system("mkdir -p ~/.vim/.tmp/netrw")
endif
if has('nvim')
set shada='1000,f1,<500,:100,/100,s10,h
else
set viminfo='1000,f1,<500,:100,/100,s10,h,n~/.vim/viminfo
endif
set backupdir=~/.vim/.tmp/backup,~/.vim/.tmp,/tmp
set undodir=~/.vim/.tmp/undo,~/.vim/.tmp,/tmp
let g:netrw_home = '~/.vim/.tmp/netrw'
let g:netrw_clipboard = 0
set completeopt=menuone,preview
" Make Vim completion popup menu work just like in an IDE
" set completeopt=longest,menuone
" inoremap <expr> <cr> pumvisible() ? "\<c-y>" : "\<c-g>u\<cr>"
" inoremap <expr> <c-n> pumvisible() ? "\<lt>c-n>" : "\<lt>c-n>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>"
" inoremap <expr> <m-;> pumvisible() ? "\<lt>c-n>" : "\<lt>c-x>\<lt>c-o>\<lt>c-n>\<lt>c-p>\<lt>c-r>=pumvisible() ? \"\\<lt>down>\" : \"\"\<lt>cr>
" Highlight VCS conflict markers
" match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
" vp doesn't replace paste buffer
function! RestoreRegister()
let @" = s:restore_reg
return ''
endfunction
function! s:Repl()
let s:restore_reg = @"
return "p@=RestoreRegister()\<cr>"
endfunction
vmap <silent> <expr> p <sid>Repl()
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
" }}}