/
.vimrc
481 lines (368 loc) · 14.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
" 0 preamble ============================================================== {{{
" My ".vimrc" contains configures options which are core to Vim and are
" enumerated by the `:options` command. It groups the options into the
" same sections given by that command and in the same order for
" reference.
"
" Occasionally, each section contains other mappings or variable
" settings relevant to the options adjacent to them.
"
" The "$HOME/.vim" directory contains everything else, either as
" individual plugins (under "$HOME/.vim/[after/]{plugin,ftplugin}/") or
" as packages (under under "$HOME/.vim/pack/*/").
set all& " set all options to their defaults
" ========================================================================= }}}
" 1 important ============================================================= {{{
set nocompatible
if has('autocmd')
au! BufEnter *
endif
" package compat via pathogen
runtime pack/default/start/pathogen/autoload/pathogen.vim
if exists("g:loaded_pathogen")
execute pathogen#infect()
execute pathogen#helptags()
endif
" ========================================================================= }}}
" 2 moving around, searching and patterns ================================= {{{
set nostartofline
set noautochdir
set wrapscan
set magic
set ignorecase
set smartcase
set gdefault
set incsearch
" ========================================================================= }}}
" 3 tags ================================================================== {{{
set showfulltag
set tags+=./tags,./.tags,tags,.tags
set tagcase=followscs
" ========================================================================= }}}
" 4 displaying text ======================================================= {{{
set scroll=7
set scrolloff=0
set nowrap
set linebreak
set display=lastline
if has('windows') && has('folding')
set fillchars= " clear defaults
set fillchars+=stl:\ " set blank space for statusline fill
set fillchars+=stlnc:\ " set blank space for statusline fill
set fillchars+=vert:\ " set blank space for vertical separator fill
set fillchars+=fold:\ " set blank space for foldtext fill
set fillchars+=diff:\ " set blank space for diff deleted lines fill
endif
set lazyredraw
set list " show non-printing characters sometimes
set listchars= " clear defaults
set listchars+=tab:›\ " " show a small chevron for a tab
set listchars+=trail:· " show a small interpunct for trailing whitespace
set listchars+=nbsp:␣ " show a small open box for non-breaking spaces
set listchars+=extends:› " show a small chevron for text to the right
set listchars+=precedes:‹ " show a small chevron for text to the left
set listchars+=eol:\ " " show nothing at the end of a line
set number
set numberwidth=5
" ========================================================================= }}}
" 5 syntax, highlighting and spelling ===================================== {{{
set background=dark
let base16colorspace=256
colorscheme base16-ocean
syntax enable
syntax sync minlines=256
set synmaxcol=300 " stop syntax highlighting this many columns out
set hlsearch
if has('guicolors')
set guicolors
endif
if has('termguicolors') && exists('$COLORTERM') && $COLORTERM ==? 'truecolor'
set termguicolors
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
set nocursorline
if exists('&colorcolumn')
let &colorcolumn=join([73,81] + range(101,999), ',')
endif
" custom highlights
hi Comment term=italic cterm=italic gui=italic
hi Keyword term=bold cterm=bold gui=bold
hi Conditional term=bold cterm=bold gui=bold
hi Define term=bold cterm=bold gui=bold
hi htmlItalic term=italic cterm=italic gui=italic
hi htmlBold term=bold cterm=bold gui=bold
hi htmlBoldItalic term=italic,bold cterm=italic,bold gui=italic,bold
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' " highlight VCS conflict markers
match ErrorMsg 'd41d8cd9-8f00-3204-a980-0998ecf8427e' " highlight empty UUID
" ========================================================================= }}}
" 6 multiple windows ====================================================== {{{
set laststatus=2
set hidden
set switchbuf=useopen,usetab
set splitbelow
set splitright
set scrollopt=ver,hor,jump
" ========================================================================= }}}
" 7 multiple tab pages ==================================================== {{{
set showtabline=2
" ========================================================================= }}}
" 8 terminal ============================================================== {{{
" allow using iterm cursor guide
if exists('$LC_TERMINAL') && $LC_TERMINAL ==? 'iterm2'
" let &t_ti .= "\<Esc>]1337;HighlightCursorLine=true\x7"
" let &t_te .= "\<Esc>]1337;HighlightCursorLine=false\x7"
endif
"set ttyscroll=0
if exists('&ttyfast') | set ttyfast | endif
set title titlestring=%<%F%=%l/%L-%P titlelen=70
" ========================================================================= }}}
" 9 using the mouse ======================================================= {{{
" mouse settings are primarily delegated to the terminus plugin
" block select with control-click-and-drag
noremap <C-LeftMouse> <LeftMouse><C-V>
noremap <C-LeftDrag> <LeftDrag>
" ========================================================================= }}}
" 10 GUI ================================================================== {{{
" this section only appears in `:options` in a GUI like MacVim or gVim
if has('gui_running')
set linespace=1
set guifont=SF\ Mono:h11
if has('transparency')
set transparency=0
endif
endif
" ========================================================================= }}}
" 11 printing ============================================================= {{{
" ========================================================================= }}}
" 12 messages and info ==================================================== {{{
set noshowmode
set showcmd
set shortmess+=I
set ruler
" ========================================================================= }}}
" 13 selecting text ======================================================= {{{
if has('clipboard')
set clipboard=unnamed
endif
"set selectmode+=mouse,key,cmd
" ========================================================================= }}}
" 14 editing text ========================================================= {{{
if has('persistent_undo')
set undolevels=10000
if exists('&undoreload')
set undoreload=10000
endif
set undofile
set undodir=~/.vim/local/undo//
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
endif
set backspace=indent,eol,start
set complete=.,w,b,u,t
set completeopt+=menuone,noselect
set whichwrap+=<>[]
set textwidth=72
set formatoptions=qrn1
set formatlistpat=^\\s*[0-9*-]\\+[\\]:.)}\\t\ ]\\s*
" set showmatch
set nojoinspaces " I only space once after a dot right now
" ========================================================================= }}}
" 15 tabs and indenting =================================================== {{{
filetype indent plugin on
" these are merely defaults
set tabstop=2
set shiftwidth=2
set smarttab
set expandtab
set smartindent
set cinoptions+=(0
" ========================================================================= }}}
" 16 folding ============================================================== {{{
set foldenable
set foldlevel=99 " Don't autofold anything
set foldlevelstart=99 " Don't autofold anything
set foldmethod=manual " allows faster editing by default
function! MyFoldText()
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
endfunction
set foldtext=MyFoldText()
" ========================================================================= }}}
" 17 diff mode ============================================================ {{{
set diffopt+=foldcolumn:0
if has('patch-8.1.0360')
set diffopt+=algorithm:histogram
set diffopt+=indent-heuristic
endif
" ========================================================================= }}}
" 18 mapping ============================================================== {{{
set notimeout
set ttimeout
set timeoutlen=100
set ttimeoutlen=100
let mapleader = ","
let maplocalleader = "\\"
" someday migrate all the mappings to their own topical plugins
" Keep search matches in the middle of the window
" nnoremap n nzzzv
" nnoremap N Nzzzv
" Same when jumping around
" nnoremap g; g;zz
" nnoremap g, g,zz
" nnoremap <c-o> <c-o>zz
" remappable because of matchit.vim
nmap <tab> %
vmap <tab> %
nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
vnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
" make search a little easier right away (less escaping)
nnoremap / /\v
vnoremap / /\v
" Sudo to write
cnoremap w!! w !sudo tee % >/dev/null
" Y behaves more like I'd expect
nnoremap Y y$
" Typos
command! -bang E e<bang>
command! -bang Q q<bang>
command! -bang W w<bang>
command! -bang QA qa<bang>
command! -bang Qa qa<bang>
command! -bang Wa wa<bang>
command! -bang WA wa<bang>
command! -bang Wq wq<bang>
command! -bang WQ wq<bang>
" Wrapped lines goes down/up to next row, rather than next line in file.
" noremap <Up> gk
" noremap <Down> gj
" noremap k gk
" noremap j gj
" inoremap <Down> <C-o>gj
" inoremap <Up> <C-o>gk
nnoremap U <c-r>
" clean trailing whitespace
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
nnoremap <leader>ww :%s/\s\+$//<cr>:let @/=''<CR>
" wrap a paragraph
vnoremap Q gq
nnoremap Q gqip
" retain selection when changing indent level
vnoremap < <gv
vnoremap > >gv
" reselect what was just pasted
nnoremap <leader>v V`]
" quickly open .vimrc
nnoremap <leader>ev :exec 'edit ' . resolve(expand($MYVIMRC))<CR>
" switch splits more easily
nnoremap <c-h> <c-w>h
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-l> <c-w>l
" nnoremap <c-left> <c-w>h
" nnoremap <c-down> <c-w>j
" nnoremap <c-up> <c-w>k
" nnoremap <c-right> <c-w>l
" move lines with leader-{j,k}, indent with leader-{h,l}
nnoremap <leader>k :m-2<CR>==
nnoremap <leader>j :m+<CR>==
nnoremap <leader>h <<
nnoremap <leader>l >>
inoremap <leader>j <Esc>:m+<CR>==gi
inoremap <leader>k <Esc>:m-2<CR>==gi
inoremap <leader>h <Esc><<`]a
inoremap <leader>l <Esc>>>`]a
vnoremap <leader>j :m'>+<CR>gv=gv
vnoremap <leader>k :m-2<CR>gv=gv
vnoremap <leader>h <gv
vnoremap <leader>l >gv
" clear old search
nnoremap <leader>/ :silent let @/ = ''<cr>
nnoremap <leader><space> :silent let @/ = ''<cr>
" " quickly create or toggle folds with the spacebar
" nnoremap <silent> <Space> @=(foldlevel('.')?'za':'l')<CR>
" vnoremap <Space> zf
cnoreabbrev <expr> git ((getcmdtype() is# ':' && getcmdline() is# 'git')?('Git'):('git'))
" Column scroll-binding on <leader>sb
noremap <silent> <leader>sb :<C-u>let @z=&so<CR>:set so=0 noscb<CR>:bo vs<CR>Ljzt:setl scb<CR><C-w>p:setl scb<CR>:let &so=@z<CR>
" ========================================================================= }}}
" 19 reading and writing files ============================================ {{{
set modeline
set writebackup
set backup
set backupcopy=yes " preserves attributes, including Finder file labels
set backupdir=~/.vim/local/backup//
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
set backupskip+=/tmp/*,/private/tmp/*
let &backupskip .= expand('$HOME') . '/.ssh/*'
set autowriteall
set autoread
set writeany
set fsync
if exists('&cryptmethod') && (v:version > 704 || (v:version == 704 && has('patch401')))
set cryptmethod=blowfish2
endif
" ========================================================================= }}}
" 20 the swap file ======================================================== {{{
set directory=~/.vim/local/swap//
if !isdirectory(expand(&directory))
call mkdir(expand(&directory), "p")
endif
set swapsync=fsync
set updatecount=10
set updatetime=500
" ========================================================================= }}}
" 21 command line editing ================================================= {{{
set history=5000
set wildmode=list:longest,full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*,*.bak,*.exe,target,tags,.tags,*/.git/*
set wildignore+=*.pyc,*.DS_Store,*.db
set wildignore+=versions/*,cache/*
set fileignorecase
set wildignorecase
set wildmenu
" ========================================================================= }}}
" 22 executing external commands ========================================== {{{
"set nowarn
" ========================================================================= }}}
" 23 running make and jumping to errors =================================== {{{
if executable('rg')
set grepprg=rg\ --smart-case\ --vimgrep
set grepformat=%f:%l:%c:%m
cnoreabbrev <expr> rg grep
elseif executable('ag')
set grepprg=ag\ --smart-case\ --vimgrep
set grepformat=%f:%l:%c:%m
cnoreabbrev <expr> ag grep
endif
" ========================================================================= }}}
" 24 language specific ==================================================== {{{
" ========================================================================= }}}
" 25 multi-byte characters ================================================ {{{
set encoding=utf-8
set fileencoding=utf-8
set termencoding=utf-8
" ========================================================================= }}}
" 26 various ============================================================== {{{
set virtualedit=all
set gdefault
set viewoptions=cursor,folds,slash,unix
if exists('&viewdir')
set viewdir=~/.vim/local/view//
if !isdirectory(expand(&viewdir))
call mkdir(expand(&viewdir), "p")
endif
endif
" ========================================================================= }}}
" vim: set fen fdm=marker vop-=folds tw=72 :