-
Notifications
You must be signed in to change notification settings - Fork 183
/
.vimrc
495 lines (392 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
" -----------------------------------------------------------------------------
" This config is targeted for Vim 8.0+ and expects you to have Plug installed.
" -----------------------------------------------------------------------------
" -----------------------------------------------------------------------------
" Plugins
" -----------------------------------------------------------------------------
" Specify a directory for plugins.
call plug#begin('~/.vim/plugged')
" Gruvbox theme.
Plug 'gruvbox-community/gruvbox'
" Integrate fzf with Vim.
Plug '~/.fzf'
Plug 'junegunn/fzf.vim'
" Better manage Vim sessions.
Plug 'tpope/vim-obsession'
" Zoom in and out of a specific split pane (similar to tmux).
Plug 'dhruvasagar/vim-zoom'
" Pass focus events from tmux to Vim (useful for autoread and linting tools).
Plug 'tmux-plugins/vim-tmux-focus-events'
" Navigate and manipulate files in a tree view.
Plug 'scrooloose/nerdtree'
" Launch Ranger from Vim.
Plug 'francoiscabrol/ranger.vim'
" Run a diff on 2 directories.
Plug 'will133/vim-dirdiff'
" Run a diff on 2 blocks of text.
Plug 'AndrewRadev/linediff.vim'
" Add spelling errors to the quickfix list (vim-ingo-library is a dependency).
Plug 'inkarkat/vim-ingo-library' | Plug 'inkarkat/vim-SpellCheck'
" Modify * to also work with visual selections.
Plug 'nelstrom/vim-visual-star-search'
" Automatically clear search highlights after you move your cursor.
Plug 'haya14busa/is.vim'
" Handle multi-file find and replace.
Plug 'mhinz/vim-grepper'
" Better display unwanted whitespace.
Plug 'ntpeters/vim-better-whitespace'
" Toggle comments in various ways.
Plug 'tpope/vim-commentary'
" Surround text with quotes, parenthesis, brackets, and more.
Plug 'tpope/vim-surround'
" Automatically set 'shiftwidth' + 'expandtab' (indention) based on file type.
Plug 'tpope/vim-sleuth'
" A number of useful motions for the quickfix list, pasting and more.
Plug 'tpope/vim-unimpaired'
" Drastically improve insert mode performance in files with folds.
Plug 'Konfekt/FastFold'
" Show git file changes in the gutter.
Plug 'mhinz/vim-signify'
" A git wrapper.
Plug 'tpope/vim-fugitive'
" Dim paragraphs above and below the active paragraph.
Plug 'junegunn/limelight.vim'
" Distraction free writing by removing UI elements and centering everything.
Plug 'junegunn/goyo.vim'
" A bunch of useful language related snippets (ultisnips is the engine).
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
" Run test suites for various languages.
Plug 'janko/vim-test'
" Languages and file types.
Plug 'cakebaker/scss-syntax.vim'
Plug 'chr4/nginx.vim'
Plug 'chrisbra/csv.vim'
Plug 'ekalinin/dockerfile.vim'
Plug 'elixir-editors/vim-elixir'
Plug 'elzr/vim-json'
Plug 'Glench/Vim-Jinja2-Syntax'
Plug 'godlygeek/tabular' | Plug 'tpope/vim-markdown'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' }
Plug 'lifepillar/pgsql.vim'
Plug 'othree/html5.vim'
Plug 'pangloss/vim-javascript'
Plug 'PotatoesMaster/i3-vim-syntax'
Plug 'stephpy/vim-yaml'
Plug 'tmux-plugins/vim-tmux'
Plug 'tpope/vim-git'
Plug 'tpope/vim-liquid'
Plug 'tpope/vim-rails'
Plug 'vim-python/python-syntax'
Plug 'vim-ruby/vim-ruby'
Plug 'wgwoods/vim-systemd-syntax'
call plug#end()
" -----------------------------------------------------------------------------
" Color settings
" -----------------------------------------------------------------------------
colorscheme gruvbox
" For Gruvbox to look correct in terminal Vim you'll want to source a palette
" script that comes with the Gruvbox plugin.
"
" Add this to your ~/.profile file:
" source "$HOME/.vim/plugged/gruvbox/gruvbox_256palette.sh"
" Gruvbox comes with both a dark and light theme.
set background=dark
" Gruvbox has 'hard', 'medium' (default) and 'soft' contrast options.
let g:gruvbox_contrast_light='hard'
" This needs to come last, otherwise the colors aren't correct.
syntax on
" -----------------------------------------------------------------------------
" Status line
" -----------------------------------------------------------------------------
" Heavily inspired by: https://github.com/junegunn/dotfiles/blob/master/vimrc
function! s:statusline_expr()
let mod = "%{&modified ? '[+] ' : !&modifiable ? '[x] ' : ''}"
let ro = "%{&readonly ? '[RO] ' : ''}"
let ft = "%{len(&filetype) ? '['.&filetype.'] ' : ''}"
let fug = "%{exists('g:loaded_fugitive') ? fugitive#statusline() : ''}"
let sep = ' %= '
let pos = ' %-12(%l : %c%V%) '
let pct = ' %P'
return '[%n] %f %<'.mod.ro.ft.fug.sep.pos.'%*'.pct
endfunction
let &statusline = s:statusline_expr()
" -----------------------------------------------------------------------------
" Change status line color for insert and replace modes
" -----------------------------------------------------------------------------
" Optimized for gruvbox:hard (both dark and light).
function! InsertStatuslineColor(mode)
if a:mode == 'i'
if (&background == 'dark')
hi StatusLine ctermfg=109 ctermbg=0 guifg=#83a598 guibg=#000000
else
hi StatusLine ctermfg=24 ctermbg=255 guifg=#076678 guibg=#ffffff
endif
elseif a:mode == 'r'
if (&background == 'dark')
hi StatusLine ctermfg=106 ctermbg=0 guifg=#98971a guibg=#000000
else
hi StatusLine ctermfg=100 ctermbg=255 guifg=#79740e guibg=#ffffff
endif
else
if (&background == 'dark')
hi StatusLine ctermfg=166 ctermbg=0 guifg=#d65d0e guibg=#000000
else
hi StatusLine ctermfg=88 ctermbg=255 guifg=#9d0006 guibg=#ffffff
endif
endif
endfunction
function! InsertLeaveActions()
if (&background == 'dark')
au InsertLeave * hi StatusLine ctermfg=239 ctermbg=223 guifg=#504945 guibg=#ebdbb2
else
au InsertLeave * hi StatusLine ctermfg=250 ctermbg=0 guifg=#d5c4a1 guibg=#000000
endif
endfunction
au InsertEnter * call InsertStatuslineColor(v:insertmode)
au InsertChange * call InsertStatuslineColor(v:insertmode)
au InsertLeave * call InsertLeaveActions()
" Ensure status line color gets reverted if exiting insert mode with CTRL + C.
inoremap <C-c> <C-o>:call InsertLeaveActions()<CR><C-c>
" -----------------------------------------------------------------------------
" Basic Settings
" Research any of these by running :help <setting>
" -----------------------------------------------------------------------------
let mapleader=" "
let maplocalleader=" "
set autoindent
set autoread
set backspace=indent,eol,start
set backupdir=/tmp//,.
set clipboard=unnamedplus
set colorcolumn=80
set complete-=i
set completeopt=menuone,preview
set cryptmethod=blowfish2
set directory=/tmp//,.
set encoding=utf-8
set expandtab smarttab
set formatoptions=tcqrn1
set hidden
set hlsearch
set ignorecase
set incsearch
set laststatus=2
set lazyredraw
set matchpairs+=<:> " Use % to jump between pairs
set modelines=2
set mouse=a
set nocompatible
set noerrorbells visualbell t_vb=
set noshiftround
set nospell
set nostartofline
set number relativenumber
set regexpengine=1
set ruler
set scrolloff=3
set shiftwidth=2
set showcmd
set showmatch
set showmode
set smartcase
set softtabstop=2
set spelllang=en_us
set splitbelow
set splitright
set tabstop=2
set textwidth=0
set ttimeout
set ttyfast
set ttymouse=sgr
set undodir=/tmp//,.
set virtualedit=block
set whichwrap=b,s,<,>
set wildmenu
set wildmode=full
set wrap
runtime! macros/matchit.vim
" -----------------------------------------------------------------------------
" Basic mappings
" -----------------------------------------------------------------------------
" Seamlessly treat visual lines as actual lines when moving around.
noremap j gj
noremap k gk
noremap <Down> gj
noremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
" Navigate around splits with a single key combo.
nnoremap <C-l> <C-w><C-l>
nnoremap <C-h> <C-w><C-h>
nnoremap <C-k> <C-w><C-k>
nnoremap <C-j> <C-w><C-j>
" Cycle through splits.
nnoremap <S-Tab> <C-w>w
" Press * to search for the term under the cursor or a visual selection and
" then press a key below to replace all instances of it in the current file.
nnoremap <Leader>r :%s///g<Left><Left>
nnoremap <Leader>rc :%s///gc<Left><Left><Left>
" The same as above but instead of acting on the whole file it will be
" restricted to the previously visually selected range. You can do that by
" pressing *, visually selecting the range you want it to apply to and then
" press a key below to replace all instances of it in the current selection.
xnoremap <Leader>r :s///g<Left><Left>
xnoremap <Leader>rc :s///gc<Left><Left><Left>
" Type a replacement term and press . to repeat the replacement again. Useful
" for replacing a few instances of the term (comparable to multiple cursors).
nnoremap <silent> s* :let @/='\<'.expand('<cword>').'\>'<CR>cgn
xnoremap <silent> s* "sy:let @/=@s<CR>cgn
" Clear search highlights.
map <Leader><Space> :let @/=''<CR>
" Format paragraph (selected or not) to 80 character lines.
nnoremap <Leader>g gqap
xnoremap <Leader>g gqa
" Prevent x from overriding what's in the clipboard.
noremap x "_x
noremap X "_x
" Prevent selecting and pasting from overwriting what you originally copied.
xnoremap p pgvy
" Keep cursor at the bottom of the visual selection after you yank it.
vmap y ygv<Esc>
" Edit Vim config file in a new tab.
map <Leader>ev :tabnew $MYVIMRC<CR>
" Source Vim config file.
map <Leader>sv :source $MYVIMRC<CR>
" Eliminate issues where you accidentally hold shift for too long with :w.
command! W write
" Toggle spell check.
map <F5> :setlocal spell!<CR>
" Toggle quickfix window.
function! QuickFix_toggle()
for i in range(1, winnr('$'))
let bnum = winbufnr(i)
if getbufvar(bnum, '&buftype') == 'quickfix'
cclose
return
endif
endfor
copen
endfunction
nnoremap <silent> <Leader>c :call QuickFix_toggle()<CR>
" Convert the selected text's title case using the external tcc script.
" Requires: https://github.com/nickjj/title-case-converter
vnoremap <Leader>tc c<C-r>=system('tcc', getreg('"'))[:-2]<CR>
" -----------------------------------------------------------------------------
" Basic autocommands
" -----------------------------------------------------------------------------
" Reduce delay when switching between modes.
augroup NoInsertKeycodes
autocmd!
autocmd InsertEnter * set ttimeoutlen=0
autocmd InsertLeave * set ttimeoutlen=50
augroup END
" Auto-resize splits when Vim gets resized.
autocmd VimResized * wincmd =
" Update a buffer's contents on focus if it changed outside of Vim.
au FocusGained,BufEnter * :checktime
" Unset paste on InsertLeave.
autocmd InsertLeave * silent! set nopaste
" Make sure all types of requirements.txt files get syntax highlighting.
autocmd BufNewFile,BufRead requirements*.txt set syntax=python
" Ensure tabs don't get converted to spaces in Makefiles.
autocmd FileType make setlocal noexpandtab
" ----------------------------------------------------------------------------
" Basic commands
" ----------------------------------------------------------------------------
" Add all TODO items to the quickfix list relative to where you opened Vim.
function! s:todo() abort
let entries = []
for cmd in ['git grep -niIw -e TODO -e FIXME 2> /dev/null',
\ 'grep -rniIw -e TODO -e FIXME . 2> /dev/null']
let lines = split(system(cmd), '\n')
if v:shell_error != 0 | continue | endif
for line in lines
let [fname, lno, text] = matchlist(line, '^\([^:]*\):\([^:]*\):\(.*\)')[1:3]
call add(entries, { 'filename': fname, 'lnum': lno, 'text': text })
endfor
break
endfor
if !empty(entries)
call setqflist(entries)
copen
endif
endfunction
command! Todo call s:todo()
" Profile Vim by running this command once to start it and again to stop it.
function! s:profile(bang)
if a:bang
profile pause
noautocmd qall
else
profile start /tmp/profile.log
profile func *
profile file *
endif
endfunction
command! -bang Profile call s:profile(<bang>0)
" -----------------------------------------------------------------------------
" Plugin settings, mappings and autocommands
" -----------------------------------------------------------------------------
" .............................................................................
" junegunn/fzf.vim
" .............................................................................
let $FZF_DEFAULT_OPTS = '--bind ctrl-a:select-all'
" Launch fzf with CTRL+P.
nnoremap <silent> <C-p> :FZF -m<CR>
" Map a few common things to do with FZF.
nnoremap <silent> <Leader><Enter> :Buffers<CR>
nnoremap <silent> <Leader>l :Lines<CR>
" Allow passing optional flags into the Rg command.
" Example: :Rg myterm -g '*.md'
command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case " . <q-args>, 1, <bang>0)
" .............................................................................
" scrooloose/nerdtree
" .............................................................................
let g:NERDTreeShowHidden=1
let g:NERDTreeAutoDeleteBuffer=1
" Open nerd tree at the current file or close nerd tree if pressed again.
nnoremap <silent> <expr> <Leader>n g:NERDTree.IsOpen() ? "\:NERDTreeClose<CR>" : bufexists(expand('%')) ? "\:NERDTreeFind<CR>" : "\:NERDTree<CR>"
" .............................................................................
" mhinz/vim-grepper
" .............................................................................
let g:grepper={}
let g:grepper.tools=["rg"]
xmap gr <plug>(GrepperOperator)
" After searching for text, press this mapping to do a project wide find and
" replace. It's similar to <leader>r except this one applies to all matches
" across all files instead of just the current file.
nnoremap <Leader>R
\ :let @s='\<'.expand('<cword>').'\>'<CR>
\ :Grepper -cword -noprompt<CR>
\ :cfdo %s/<C-r>s//g \| update
\<Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>
" The same as above except it works with a visual selection.
xmap <Leader>R
\ "sy
\ gvgr
\ :cfdo %s/<C-r>s//g \| update
\<Left><Left><Left><Left><Left><Left><Left><Left><Left><Left><Left>
" .............................................................................
" ntpeters/vim-better-whitespace
" .............................................................................
let g:strip_whitespace_confirm=0
let g:strip_whitespace_on_save=1
" .............................................................................
" Konfekt/FastFold
" .............................................................................
let g:fastfold_savehook=0
let g:fastfold_fold_command_suffixes=[]
" .............................................................................
" junegunn/limelight.vim
" .............................................................................
let g:limelight_conceal_ctermfg=244
" .............................................................................
" iamcco/markdown-preview.nvim
" .............................................................................
let g:mkdp_refresh_slow=1
let g:mkdp_markdown_css='/home/nick/.local/lib/github-markdown-css/github-markdown.css'
" .............................................................................
" iamcco/markdown-preview.nvim
" .............................................................................
let g:mkdp_refresh_slow=1
let g:mkdp_markdown_css='/home/nick/.local/lib/github-markdown-css/github-markdown.css'