-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.vimrc
More file actions
655 lines (516 loc) · 15.8 KB
/
.vimrc
File metadata and controls
655 lines (516 loc) · 15.8 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
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
" Vim-PLug core
let vimplug_exists=expand('~/.vim/autoload/plug.vim')
if !filereadable(vimplug_exists)
if !executable("curl")
echoerr "You have to install curl or first install vim-plug yourself!"
execute "q!"
endif
echo "Installing Vim-Plug..."
echo ""
silent exec "!\curl -fLo " . vimplug_exists . " --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
let g:not_finish_vimplug = "yes"
autocmd VimEnter * PlugInstall
endif
" Required:
call plug#begin(expand('~/.vim/plugged'))
" Fuzzy search
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
Plug 'junegunn/fzf.vim'
" colorscheme
Plug 'altercation/vim-colors-solarized'
" syntax checker
Plug 'w0rp/ale'
" git
Plug 'tpope/vim-git'
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
" editing
Plug 'tpope/vim-commentary'
Plug 'kana/vim-smartinput'
Plug 'godlygeek/tabular'
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
" snippets
Plug 'honza/vim-snippets'
" programming languages
" go
Plug 'fatih/vim-go', { 'for': 'go', 'do': ':GoInstallBinaries' }
" python
Plug 'davidhalter/jedi-vim', { 'for': 'python' }
" rails
Plug 'tpope/vim-rails'
" css
Plug 'ap/vim-css-color', { 'for': ['css'] }
" language pack
Plug 'sheerun/vim-polyglot'
" writing
Plug 'junegunn/goyo.vim', { 'on': 'Goyo' }
Plug 'junegunn/limelight.vim', { 'on': 'Goyo' }
"" Include user's extra bundle
if filereadable(expand("~/.vimrc.local.bundles"))
source ~/.vimrc.local.bundles
endif
call plug#end()
" Required: Enable detection, plugins and indenting in one step
filetype plugin indent on
" General settings =============================================================
set relativenumber
set number
set showcmd
set showmode
set showmatch
set autoread
set autowriteall
set splitbelow splitright
set lazyredraw
set mouse=a
set pastetoggle=<F2>
set nrformats-=octal
set fileformats="unix,dos,mac"
set switchbuf=useopen
set history=100
set viminfo='20,\"80
set shell=/bin/bash
set shortmess+=c
set signcolumn=yes
"set ruler
"set colorcolumn=81
"set cursorline
" Encoding
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8
set ttyfast
set binary
set bomb
" Fix backspace indent
set backspace=indent,eol,start
" Tabs
set smarttab
set expandtab
set tabstop=2
set softtabstop=2
set shiftwidth=2
" Enable hidden buffers
set hidden
" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
" Turn backup off
set nobackup
set noswapfile
set nowritebackup
" Highlighting
syntax on
set background=dark
set t_Co=256
set t_ut=
let g:solarized_termtrans = 1
let g:solarized_termcolors = 16
let g:solarized_visibility = "high"
let g:solarized_contrast = "high"
silent! colorscheme solarized
" Lower the delay of escaping out of other modes
set timeout timeoutlen=1000 ttimeoutlen=0
" Text display settings
set wrap
set showbreak=...
set linebreak
set linespace=4
set whichwrap+=h,l,<,>,[,]
" Don't show invisible characters
set nolist
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
" Indenting
set autoindent
set copyindent
set shiftround
" Scrolling
set scrolloff=10
set scrolljump=3
set sidescrolloff=10
set sidescroll=1
" Folding
set foldmethod=indent
set foldnestmax=5
set foldlevel=5
set foldcolumn=0
set foldlevelstart=99
set foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo " which commands trigger auto-unfold
" Turn bells off
set novisualbell
set noerrorbells
" Auto complete
set completeopt=longest,menuone
set wildmode=list:longest,list:full
set wildmenu
set wildignore=*~,*.o,*.a,*.so,*.bak,*.pyc,*.class,*.db,*.sqlite
set wildignore+=*.gem,*.jar,*.zip,*.gz
set wildignore+=.git,.hg,.svn
set wildignore+=log/**
set wildignore+=tmp/**
set wildignore+=vendor/rails/**
set wildignore+=vendor/cache/**
set wildignore+=*.png,*.jpg,*.gif,*.ico,*.bmp,*.pdf
" save automatically
set updatetime=300
au CursorHold * silent! update
" Status line ==================================================================
" always a status line
set laststatus=2
hi User1 ctermbg=Black ctermfg=Green cterm=bold
hi User2 ctermbg=Black ctermfg=DarkGreen
hi User3 ctermbg=Black ctermfg=White cterm=bold
hi User4 ctermbg=Black ctermfg=Green
set statusline=
" git current branch
set statusline+=%1*\ %{fugitive#head()}\ %*
" tail of the filename
set statusline+=%2*\ %f\ %*
" flags
set statusline+=%3*
set statusline+=%H " help file flag
set statusline+=%M " modified flag
set statusline+=%R " read only flag
set statusline+=\ %*
" left/right separator
set statusline+=%2*%=
set statusline+=%4*
set statusline+=\ %4*
set statusline+=%{strlen(&fenc)?&fenc:&enc} " encoding
set statusline+=\ \|\ %4*
set statusline+=%{strlen(&ft)?&ft:'none'} " filetype
set statusline+=\ \|\ %4*
" document details
set statusline+=%4*
set statusline+=%c, " cursor column
set statusline+=%l/%L " cursor line/total lines
set statusline+=\ %P " percent through file
set statusline+=\ %*
" Mappings ====================================================================
" Map leader to ,
" let mapleader=','
nnoremap ; :
" Avoid accidental hits of <F1> while aiming for <Esc>
map! <F1> <Esc>
" Quickly get out of insert mode without your fingers having to leave the home row
inoremap jj <Esc>
" Make possible to navigate within lines of wrapped lines
nnoremap j gj
nnoremap k gk
set fo=l
" Speed up scrolling of the viewport slightly
nnoremap <C-e> 2<C-e>
nnoremap <C-y> 2<C-y>
" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
nnoremap <leader>w <C-w>v<C-w>l
" Switch to previous split
nnoremap <leader>l <C-w>p
" Maximize current split
nnoremap <Leader>m <C-w>_<C-w><Bar>
" Complete whole filenames/lines with a quicker shortcut key in insert mode
imap <C-f> <C-x><C-f>
imap <C-l> <C-x><C-l>
" Quick yanking to the end of the line
nmap Y y$
" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
" Clears the search register
nmap <silent> <leader>/ :nohlsearch<CR>
" Quick alignment of text
nmap <leader>al :left<CR>
nmap <leader>ar :right<CR>
nmap <leader>ac :center<CR>
" Pull word under cursor into LHS of a substitute (for quick search and replace)
nmap <leader>z :%s#\<<C-r>=expand("<cword>")<CR>\>#
" Inserts the path of the currently edited file into a command
cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>
" Sudo to write
cmap w!! w !sudo tee % >/dev/null
" Folding
nnoremap <Space> za
vnoremap <Space> za
" Reselect text that was just pasted with ,v
nnoremap <leader>v V`]
" Quickly close the current window
nnoremap <leader>q :q<CR>
" Quit all, very useful in vimdiff
nnoremap Q :qa!<cr>
" Index ctags from any project
map <leader>ct :!ctags -R .<CR>
" spell check
map <leader>s :set spell<CR>
"set spelllang=en_us
" make code and open the results pane
nmap <F5> :make<CR>:copen<CR>
" tabedit shortcuts
map <leader>0 :tablast<CR>
map <leader>1 1gt
map <leader>2 2gt
map <leader>3 3gt
map <leader>4 4gt
map <leader>5 5gt
map <leader>6 6gt
map <leader>7 7gt
map <leader>8 8gt
map <leader>9 9gt
map <leader>j :tabprev<CR>
map <leader>k :tabnext<CR>
map <C-t> <ESC>:tabnew<CR>
"map <C-o> :tabonly<CR>
" Indent lines
nmap <Left> <<
nmap <Right> >>
vmap <Left> <gv
vmap <Right> >gv
" Bubble single lines
nmap <Up> [e
nmap <Down> ]e
" Bubble multiple lines
vmap <Up> [egv
vmap <Down> ]egv
" Move line
nnoremap <silent> <Down> @='"zdd"zp'<CR>
nnoremap <silent> <Up> @='k"zdd"zpk'<CR>
vnoremap <silent> <Down> @='"zx"zp`[V`]'<CR>
vnoremap <silent> <Up> @='"zxk"zP`[V`]'<CR>
" Plugins settings =============================================================
" ale
set completeopt+=noinsert
set omnifunc+=ale#completion#OmniFunc
let g:ale_fix_on_save = 0
let g:ale_completion_enabled = 1
let g:ale_linters = {
\ 'go': ['golangci-lint'],
\ 'python': ['flake8'],
\ 'ruby': ['rubocop']
\ }
let g:ale_fixers = {
\ 'go': ['gofmt'],
\ 'python': ['flake8'],
\ 'ruby': ['rubocop']
\ }
nmap <silent> <leader>at :ALEToggle<cr>
nmap <silent> <leader>an :ALENext<cr>
nmap <silent> <leader>ap :ALEPrevious<cr>
nmap <silent> <leader>af :ALEFix<cr>
" netrw
" % new file
" d new directory
" D delete file/directory
" R rename
" -- C-f quickfix modal
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 0
let g:netrw_altv = 1
let g:netrw_winsize = 20
let g:netrw_list_hide='.pyc,.git,tmp,.bundle,.cache,node_modules,.node-gyp,.yarn'
nnoremap - :Explore<CR>
noremap <Leader><space> :Lexplore<CR>
" fzf
" default fzf layout
" - down / up / left / right
let g:fzf_layout = { 'down': '~50%' }
" Customize fzf colors to match your color scheme
" - fzf#wrap translates this to a set of `--color` options
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" Enable per-command history
let g:fzf_history_dir = '~/.local/share/fzf-history'
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
" [[B]Commits] Customize the options used by 'git log':
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
"[Commands] --expect expression for directly executing the command
let g:fzf_commands_expect = 'alt-enter'
" maps fzf
map <Leader>o :Files<CR>
map <Leader>b :Buffers<CR>
map <Leader>fg :GFiles?<CR>
map <Leader>fG :GFiles<CR>
map <Leader>fl :BLines<CR>
map <Leader>fL :Lines<CR>
map <Leader>fh :History<CR>
map <Leader>fH :History/<CR>
map <Leader>a :Rg<CR>
imap <c-x><c-k> <plug>(fzf-complete-word)
imap <c-x><c-f> <plug>(fzf-complete-path)
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
imap <c-x><c-l> <plug>(fzf-complete-line)
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview(), <bang>0)
" commentary
map <leader>' :Commentary<CR>
" coc
let g:coc_snippet_next = '<c-j>'
let g:coc_snippet_prev = '<c-k>'
let g:coc_global_extensions = ['coc-snippets', 'coc-tabnine']
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
nmap <silent> gd <Plug>(coc-definition)
imap <C-l> <Plug>(coc-snippets-expand)
vmap <C-j> <Plug>(coc-snippets-select)
imap <C-j> <Plug>(coc-snippets-expand-jump)
" jedi-vim
let g:jedi#popup_on_dot = 0
let g:jedi#goto_assignments_command = "<leader>g"
let g:jedi#goto_definitions_command = "<leader>d"
let g:jedi#documentation_command = "K"
let g:jedi#usages_command = "<leader>n"
let g:jedi#rename_command = "<leader>r"
let g:jedi#show_call_signatures = "0"
" let g:jedi#completions_command = "<C-Space>"
let g:jedi#smart_auto_mappings = 0
" ruby
let g:rubycomplete_buffer_loading = 1
let g:rubycomplete_classes_in_global = 1
let g:rubycomplete_rails = 1
" golang
" let g:go_bin_path = expand("~/bin")
let g:go_list_type = "quickfix"
let g:go_fmt_command = "goimports"
let g:go_fmt_fail_silently = 1
let g:go_dispatch_enabled = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_structs = 1
let g:go_highlight_generate_tags = 1
let g:go_highlight_space_tab_error = 0
let g:go_highlight_array_whitespace_error = 0
let g:go_highlight_trailing_whitespace_error = 0
let g:go_highlight_extra_types = 1
" limelight
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 120
let g:limelight_default_coefficient = 0.7
autocmd! User GoyoEnter Limelight
autocmd! User GoyoLeave Limelight!
" Quickfix window (open/close using F12) =======================================
nmap <silent> <F12> :QFix<CR>
command! -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
if exists("g:qfix_win") && a:forced == 0
cclose
unlet g:qfix_win
else
copen 10
let g:qfix_win = bufnr("$")
endif
endfunction
" Autocmd rules ================================================================
" Remember cursor position
augroup vimrc-remember-cursor-position
autocmd!
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
augroup END
augroup templates
autocmd BufNewFile *_controller.rb 0r ~/.vim/templates/rails_controller.rb
augroup END
au BufRead,BufNewFile,BufWrite nginx.* setf nginx
au BufRead,BufNewFile,BufWrite *.json setf javascript
au BufRead,BufNewFile,BufWrite afiedt.buf setf sql
au BufRead,BufNewFile,BufWrite .dir_colors,.dircolors,/etc/DIR_COLORS setf dircolors
au BufRead,BufNewFile,BufWrite {*.json,,*.py,*.coffee,*.yaml,*.yml} set foldmethod=indent
augroup RemovingTrailingWhitespace
autocmd!
autocmd BufWritePre {*.rb,*.go,*.py,*.css,*.scss,*.js} %s/\s\+$//e
augroup END
augroup ShowColumn
autocmd!
autocmd FileType python,slim set cursorcolumn
augroup END
augroup surround
let quote_close = { "'":"'", "`":"`", "\"":"\"", "(":")", "{":"}", "[":"]"}
for quote_in in ["'", "`", "\"", "(", "{", "["]
execute "nmap ds" . quote_in . " di" . quote_in . "hPli<Delete><Delete><Esc>"
for quote_out in ["'", "`", "\"", "(", "{", "["]
execute "nmap cs" . quote_in . quote_out . " di". quote_in . "hi" . quote_out . get(quote_close, quote_out) . "<Esc>plli<Delete><Delete><Esc>h"
endfor
endfor
augroup END
augroup CallInterpreter
let b:cmd = ''
autocmd!
autocmd FileType go let b:cmd = 'go %'
autocmd FileType python let b:cmd = 'python %'
autocmd FileType ruby let b:cmd = 'ruby %'
autocmd FileType sh let b:cmd = 'bash %'
nnoremap <F9> :execute ':below terminal ++rows=10 '.b:cmd<CR>
nnoremap <F10> :make<CR>
nnoremap <F11> :make test<CR>
augroup END
augroup MakeQuickFix
autocmd!
autocmd QuickFixCmdPost * :copen
augroup END
" 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
" Golang
augroup go
au!
au Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
au Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
au Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
au Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
au FileType go nmap <Leader>dd <Plug>(go-def-vertical)
au FileType go nmap <Leader>dv <Plug>(go-doc-vertical)
au FileType go nmap <Leader>db <Plug>(go-doc-browser)
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>t <Plug>(go-test)
au FileType go nmap <Leader>gt <Plug>(go-coverage-toggle)
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <silent> <Leader>l <Plug>(go-metalinter)
au FileType go nmap <C-g> :GoDecls<cr>
au FileType go nmap <leader>dr :GoDeclsDir<cr>
au FileType go imap <C-g> <esc>:<C-u>GoDecls<cr>
au FileType go imap <leader>dr <esc>:<C-u>GoDeclsDir<cr>
au FileType go nmap <leader>rb :<C-u>call <SID>build_go_files()<CR>
au BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4 softtabstop=4
augroup END
" Include user's local vim config
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif