-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
418 lines (333 loc) · 12.5 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
" -----------------------------------------------------------------------------
" This config is targeted for Vim 8.0+ and expects you to have Plug installed.
" -----------------------------------------------------------------------------
" -----------------------------------------------------------------------------
" Plugins
" -----------------------------------------------------------------------------
" Attempt to automatically install Plug if not 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
" Specify a directory for plugins.
call plug#begin('~/.vim/plugged')
" Gruvbox theme.
Plug 'morhetz/gruvbox'
" Fancy start screen
Plug 'mhinz/vim-startify'
" Integrate fzf with Vim.
Plug '~/.fzf'
Plug 'junegunn/fzf.vim'
" Zoom in and out of a specific split pane (similar to tmux).
Plug 'dhruvasagar/vim-zoom'
" 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'
" 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'
" 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'
" 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 'plasticboy/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 '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'
Plug 'LukeGoodsell/nextflow-vim'
call plug#end()
" -----------------------------------------------------------------------------
" 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()
" -----------------------------------------------------------------------------
" 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
" -----------------------------------------------------------------------------
" 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,unnamed
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.
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
nnoremap <Down> gj
nnoremap <Up> gk
vnoremap <Down> gj
vnoremap <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
" 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=500
augroup END
" Auto-resize splits when Vim gets resized.
autocmd VimResized * wincmd =
" 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
" ----------------------------------------------------------------------------
" 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 -niI -e TODO -e FIXME -e XXX 2> /dev/null',
\ 'grep -rniI -e TODO -e FIXME -e XXX * 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>
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction
" CTRL+Q (combined with CTRL+A) to put search results into the quickfix.
" CTRL+Y to copy the highlighted file path to the clipboard.
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit',
\ 'ctrl-y': {lines -> setreg('*', join(lines, "\n"))}}
" .............................................................................
" 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>"
" .............................................................................
" Konfekt/FastFold
" .............................................................................
let g:fastfold_savehook=0
let g:fastfold_fold_command_suffixes=[]
" .............................................................................
" junegunn/limelight.vim
" .............................................................................
let g:limelight_conceal_ctermfg=244
" .............................................................................
" plasticboy/vim-markdown
" .............................................................................
autocmd FileType markdown let b:sleuth_automatic=0
autocmd FileType markdown set conceallevel=0
autocmd FileType markdown normal zR
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_frontmatter=1
" .............................................................................
" 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'