-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
428 lines (330 loc) · 10.7 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
" vim: et sts=2 sw=2
" vim: fdm=marker
set encoding=utf-8
scriptencoding utf-8
unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim
" on windows and not cygwin
let g:on_windows = (has('win32') || has('win64'))
let g:myvim = $HOME . (g:on_windows ? '/vimfiles' : '/.vim')
let g:vimcache = $HOME . '/.cache/vim'
let s:filename = expand('<sfile>')
" Set up plug and plugins {{{
call plug#begin(g:myvim . '/bundle')
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'lfv89/vim-interestingwords'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'ciaranm/securemodelines'
Plug 'editorconfig/editorconfig-vim'
Plug 'wsdjeg/vim-fetch'
Plug 'tpope/vim-vinegar'
Plug 'mbbill/undotree', {'on': 'UndotreeToggle'}
Plug 'majutsushi/tagbar', {'on': 'TagbarToggle'}
Plug 'godlygeek/tabular'
Plug 'tomtom/tcomment_vim'
Plug 'tpope/vim-unimpaired'
Plug 'kshenoy/vim-signature'
Plug 'lifepillar/vim-mucomplete'
Plug 'tpope/vim-endwise'
Plug 'kana/vim-textobj-user'
Plug 'glts/vim-textobj-comment'
Plug 'vimwiki/vimwiki'
Plug 'Shougo/vinarise.vim'
Plug 'asciidoc/vim-asciidoc'
Plug 'vim-perl/vim-perl', {'branch': 'dev'}
Plug 'sheerun/vim-polyglot'
Plug 'yko/mojo.vim'
Plug 'powerman/vim-plugin-viewdoc'
let g:no_viewdoc_abbrev = 1
let g:polyglot_disabled = ['autoindent', 'sensible', 'vifm', 'perl', 'go']
try
execute 'source ' . s:filename . '.local-pre'
catch
endtry
call plug#end()
" }}}
" Key maps {{{
nnoremap <silent> <F2> :20Lexplore<CR>
nnoremap <silent> <F3> n
nnoremap <silent> <S-F3> N
noremap <silent> <F4> :let v:hlsearch = !v:hlsearch<CR>
nnoremap <silent> <F5> :UndotreeToggle<CR>
nnoremap <silent> <F8> :TagbarToggle<CR>
" let F4, :noh work as-is in insert mode
imap <F4> <C-O><F4>
cmap <F3> <CR>
" chdir to the directory of the open buffer
noremap <leader>cd :cd %:p:h<cr>:pwd<cr>
noremap <leader>pp :setlocal paste!<cr>
noremap <leader>cc :MUcompleteAutoToggle<cr>
" faster window nav
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-\> <C-w>p
" navigate by on-screen lines
nnoremap <expr> j v:count ? 'j' : 'gj'
nnoremap <expr> k v:count ? 'k' : 'gk'
" alt buffer
nnoremap gb <C-^>
nnoremap gB :ls<CR>:b<Space>
" Select last paste, in the same mode it was pasted in
nnoremap <expr> gV '`[' . strpart(getregtype(), 0, 1) . '`]'
" Use ltag over tselect
nnoremap g<C-]> :call vimrc#Ltag(expand('<cword>'))<CR>
" clear all interestingwords with \\k since \K is ri.vim
nnoremap <silent> <leader><leader>k :call UncolorAllWords()<CR>
" mark line
nmap <leader>l V<leader>k
" use Grep for a recursive *
nnoremap g* :Grep<CR>
" K: doc, gKK: doc current filename
nnoremap gKK :call ViewDoc('doc', expand('%:p'))<CR>
" Tabular shortcuts
noremap <leader>ta :Tabularize first_arrow<CR>
noremap <leader>te :Tabularize first_eq<CR>
noremap <leader>tc :Tabularize first_colon<CR>
noremap <leader>tm :Tabularize methods<CR>
noremap <silent> <leader>a :call vimrc#AutoFmtToggle()<CR>
" Commands & Aliases {{{
command! -nargs=+ CAlias call vimrc#CommandAlias(<f-args>)
command! Gcd call vimrc#Gcd()
command! Hgcd call vimrc#Hgcd()
command! SyntaxCompleteOn setl omnifunc=syntaxcomplete#Complete
command! Mksession execute "mksession! " . v:this_session
command! PruneSession call vimrc#PruneSession()
command! -nargs=* -complete=file Tig call tig#Tig(<f-args>)
command! TigBlame call tig#TigBlame()
command! TigLog call tig#Tig('log', '-p', '--', expand('%'))
command! -nargs=* -complete=file Grep call vimrc#Grep(<f-args>)
CAlias Ag Grep
CAlias grep Grep
CAlias Q q
CAlias Qa qa
CAlias W w
CAlias gcd Gcd
CAlias hgcd Hgcd
" make these default to one window/buffer too
CAlias doc ViewDoc!
CAlias help ViewDocHelp!
CAlias man ViewDocMan!
CAlias perldoc ViewDocPerl!
"}}}
"}}}
" General settings {{{
set background=dark
set hlsearch
set ignorecase
set smartcase
if has('gui_running') || $LANG =~# 'UTF-8'
let &listchars = "tab:⇥·,trail:◼,nbsp:◻,extends:»,precedes:«"
let &fillchars = "fold: ,vert:│"
else
let &listchars = "tab:>-,trail:-,nbsp:%,extends:»,precedes:«"
let &fillchars = "fold: "
endif
set linebreak
let &showbreak = "» "
set breakindent
set breakindentopt=min:66,shift:2
set virtualedit=block
set autoindent
set smarttab
set expandtab
set shiftwidth=2
set shiftround
set formatoptions=cqln1j
if has("patch-8.1.0360")
set diffopt+=algorithm:patience
endif
set splitright splitbelow
set scrolloff=15
set sidescrolloff=10
set laststatus=2
set noshowmode
set wildignorecase
set shortmess+=c
set noerrorbells
set belloff=all
set autowriteall
set autoread
set ttimeoutlen=25
set synmaxcol=350
set tags+=.tags,./.tags;
" Ignore compiled files and repositories
set wildignore=*.o,*~,*.pyc
if g:on_windows
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
else
set wildignore+=.git\*,.hg\*,.svn\*
endif
" Don't assume to scan includes when autocompleting
set complete-=i complete-=t
set completeopt+=menuone,noselect
" Never open with folds collapsed
set nofoldenable
" keep the junk out (imo)
set sessionoptions=buffers,curdir,localoptions
" Enable enhanced % matching in ruby
runtime macros/matchit.vim
for subdir in ['backup', 'tmp', 'undo']
call vimrc#PrepDir(g:vimcache . '/' . subdir)
" call vimrc#PruneFiles(g:vimcache . '/' . subdir, 60)
endfor
call vimrc#PrepDir(g:vimcache . '/session')
set backup
let &backupdir = g:vimcache . '/backup//,.'
let &directory = g:vimcache . '/tmp//,.'
if has('persistent_undo')
set undofile
let &undodir = g:vimcache . '/undo//,.'
endif
if executable('ag')
let &grepprg = "ag --vimgrep"
set grepformat^=%f:%l:%c:%m,%f
set errorformat+=%f
endif
let g:jellybeans_overrides = {
\ 'SignColumn': {'ctermbg': 235, 'guibg':'222222'},
\ }
colorscheme jellybeans
" }}}
" Autocmds {{{
augroup vimrc
autocmd!
autocmd WinLeave * if !pumvisible() | stopinsert | endif
" complement to autowriteall
autocmd FocusLost * silent! wa
" Make paths when writing, as necessary
autocmd BufWritePre * :call vimrc#MkNonExDir(expand('<afile>'), +expand('<abuf>'))
if ! &diff
" set and load a session based on servername
autocmd VimEnter * nested call vimrc#AutoSessionCheck()
" Jump to last known pos
autocmd BufReadPost *
\ if &filetype !~# 'mail\|^git\|^hg' && line("'\"") >= 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Simple highlight conflict markers
autocmd BufReadPost *
\ match Error "^\([<>|]\)\{7} \@=\|^=\{7}$"
endif
" Simplify noisy ltag output
autocmd BufReadPost quickfix
\ if w:quickfix_title =~# '^:ltag' |
\ setl modifiable |
\ silent exe ':%s/\^\\V\s*\|\\\$|.*//g' |
\ setl nomodifiable |
\ endif
autocmd BufReadPost quickfix nmap <buffer> q <C-w>c
" Neomutt changed their tmpfile pattern, ugh
autocmd BufNewFile,BufRead neomutt-*-\w\+ setf mail
augroup END
" clear defaults.vim 'jump to last known pos'
augroup vimStartup | au! | augroup END
" https://mjj.io/2015/01/27/encrypting-files-with-gpg-and-vim/
" hacked to work with vimwiki
augroup encrypted
autocmd!
autocmd BufReadPre,FileReadPre *.gpg,*.gpg.* setl noswapfile noundofile nobackup viminfo=
autocmd BufReadPost *.gpg,*.gpg.* call vimrc#SafeFilterFile('gpg2 -d')
autocmd BufWritePre *.gpg,*.gpg.* call vimrc#SafeFilterFile('gpg2 -se -a --default-recipient-self')
autocmd BufWritePost *.gpg,*.gpg.* :sil undo
augroup END
"}}}
" Perl type-specific settings {{{
let perl_include_pod = 1
let perl_sub_signatures = 1
let perl_sync_dist = 200
let g:perl_compiler_force_warnings = 0
" }}}
" Plugin settings {{{
let g:plug_threads = 3
let g:netrw_altfile = 1
let g:netrw_use_errorwindow = 0
">> mucomplete
" enable and prefer local buffer before tags
let g:mucomplete#completion_delay = 300
let g:mucomplete#chains = {
\ 'default': ['path', 'c-n', 'omni', 'tags', 'dict', 'uspl'],
\}
">> Vimwiki
let g:vimwiki_auto_chdir = 1
let g:vimwiki_auto_header = 1
let g:vimwiki_ext2syntax = {}
let g:vimwiki_list = [
\ {
\ 'path': '~/vimwiki/',
\ 'auto_tags': 1, 'auto_toc': 1, 'automatic_nested_syntaxes': 1
\ },
\ {
\ 'path': '~/SynologyDrive/vimwiki',
\ 'auto_tags': 1, 'auto_toc': 1, 'automatic_nested_syntaxes': 1
\ }
\ ]
">> Viewdoc
let g:viewdoc_open = 'topleft new'
let g:viewdoc_winwidth_max = 100
">> Undotree
let g:undotree_SplitWidth = 45
let g:undotree_SetFocusWhenToggle = 1
let g:undotree_ShortIndicators = 1
let g:undotree_DiffCommand = "diff -dp -U 1"
">> Tagbar
let g:tagbar_autoclose = 1
let g:tagbar_autofocus = 1
let g:tagbar_compact = 1
let g:tagbar_width = 30
" tagbar languages in plugin/tagbar-types.vim
">> Airline
let g:airline#extensions#whitespace#enabled = 0
let g:airline_powerline_fonts = 0
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_min_count = 2
let g:airline#extensions#tabline#tab_nr_type = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
let g:airline#extensions#tabline#buffer_nr_format = '%s:'
let g:airline#extensions#tabline#buffers_label = 'BUF'
let g:airline#extensions#tabline#tabs_label = 'TAB'
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = ' '
let g:airline#extensions#tabline#right_sep = ' '
let g:airline#extensions#tabline#right_alt_sep = ' '
let g:airline#extensions#tabline#ignore_bufadd_pat =
\ '\c\v^__tagbar|^[doc\d*\]$|^diffpanel'
let g:airline#extensions#branch#format = 2
">> interestingwords
" These are jellybeans colors and some complements
let g:interestingWordsGUIColors = ['#C4A258','#6AADA0', '#71B9F8', '#A037B0', '#CF6A4C', '#D8AD4C']
let g:interestingWordsTermColors = ['179', '73', '75', '133', '167', '136']
" }}}
" {{{ Commands
" Preview markdown mail -- I edit with headers so I box them in a code block.
command! MailPreview enew | set bt=nofile | 0r # | exe 'norm! 0O```<Esc>}O```' | silent exe '%!mutt-md2html | mutt-html2txt' | 0
command! MailPreviewHTML enew | set bt=nofile | setf html | 0r # | exe 'norm! 0O```<Esc>}O```' | silent exe '%!mutt-md2html' | 0
" }}}
" Local stuff, finish up
try
execute 'source ' . s:filename . '.local'
catch
endtry
" {{{ Terminal tweaks
" vertical bar in insert mode.
if &term =~# '^\(xterm\|screen\|rxvt\)'
let &t_SI = "\e[5 q"
let &t_EI = "\e[0 q"
if exists("$TMUX")
let &t_SI = "\ePtmux;" . substitute(&t_SI, "\e", "\e\e", 'g') . "\e\\"
let &t_EI = "\ePtmux;" . substitute(&t_EI, "\e", "\e\e", 'g') . "\e\\"
endif
endif
if $TERM =~# 'rxvt-unicode'
set ttymouse=urxvt
set mouse=a
map <Esc>[7~ <Home>
map <Esc>[8~ <End>
endif
" }}}