forked from holman/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.vim
611 lines (501 loc) · 16.3 KB
/
init.vim
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
" vim: filetype=vim foldmethod=marker foldlevel=0 foldcolumn=3
"
" File: init.vim (Neovim configuration)
" Github: http://github.com/dzackgarza/dotfiles
" Maintainer:
" _____ ______ ______ ______ __ __ ______ ______ ______ ______ ______
" /\ __-. /\___ \ /\ __ \ /\ ___\ /\ \/ / /\ ___\ /\ __ \ /\ == \/\___ \ /\ __ \
" \ \ \/\ \ \/_/ /__\ \ __ \\ \ \____\ \ _"-. \ \ \__ \\ \ __ \\ \ __<\/_/ /__\ \ __ \
" \ \____- /\_____\\ \_\ \_\\ \_____\\ \_\ \_\ \ \_____\\ \_\ \_\\ \_\ \_\/\_____\\ \_\ \_\
" \/____/ \/_____/ \/_/\/_/ \/_____/ \/_/\/_/ \/_____/ \/_/\/_/ \/_/ /_/\/_____/ \/_/\/_/
"
" 人 人 人 人
" ( ゚ー゚) ( ゚ー゚) ( ゚ー゚) ( ゚ー゚)
"  ̄ ̄  ̄ ̄  ̄ ̄  ̄ ̄
" ┏━━━━━━━━━━━━━━━━━━━━━┓━━━━━━━━━━━━━━━━━━━━━━━━┓
" ┃⇒ Attack ┃ Items .┃
" ┃ Spells ┃ Equipment .┃
" ┃ Skills ┃ Psyche Up .┃
" ┃ Defend ┃ Flee .┃
" ┗━━━━━━━━━━━━━━━━━━━━━┛━━━━━━━━━━━━━━━━━━━━━━━━┛
" {{{ Boilerplate
set nocompatible
filetype plugin on
set termguicolors " enable true colors support
" }}}
" {{{ Plugins
call plug#begin()
Plug 'vim-pandoc/vim-pandoc-syntax'
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'tomtom/tlib_vim'
Plug 'vim-voom/VOoM'
"let g:voom_tab_key = "<c-q>"
"let g:voom_return_key = '<CR>'
" Automatically expand to math tex QUICKLY
Plug 'dzackgarza/quicktex'
Plug 'lervag/vimtex'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'evansalter/vim-checklist'
"""""""" Ultisnips
"Plug 'sirver/ultisnips'
"let g:UltiSnipsExpandTrigger = '<nop>'
"let g:UltiSnipsJumpForwardTrigger = '<c-p>'
"let g:UltiSnipsJumpBackwardTrigger = '<c-s-L>'
"let g:UltiSnipsRemoveSelectModeMappings = 0
"let g:UltiSnipsSnippetDirectories=["/home/zack/dotfiles/snippets"]
"let g:UltiSnipsEditSplit="horizontal"
""""""""""" Autocomplete
Plug 'neoclide/coc.nvim', {'branch': 'release'}
let g:coc_config_home = "~/dotfiles"
let g:coc_global_extensions = [
\ 'coc-vimtex',
\ 'coc-dictionary',
\ 'coc-word',
\ 'coc-spell-checker',
\ 'coc-snippets',
\]
imap <C-l> <Plug>(coc-snippets-expand)
inoremap <silent><expr> <NUL> coc#refresh()
inoremap <silent><expr> <Tab> pumvisible() ? coc#_select_confirm() : "\<C-g>u\<Tab>"
inoremap <expr> <cr> pumvisible() ? "<C-e><CR>" : "\<C-g>u\<CR>"
"""""coc-snippets test
set dictionary+=~/Notes/corpus.add
set dictionary+=~/Notes/mathdict.utf-8.add.spl
"set complete+=kspell
set spelllang=en
set spellfile=/home/dzack/Notes/mathdict.utf-8.add
""""""""
" Commands
" Nerdcommenter: toggle multiple lines as comments
Plug 'scrooloose/nerdcommenter'
"Plug 'Townk/vim-autoclose'
"Plug 'ferrine/md-img-paste.vim'
"let g:mdip_imgdir = 'figures'
Plug 'godlygeek/tabular'
Plug 'dhruvasagar/vim-table-mode'
" Layout and Functionality
Plug 'preservim/nerdtree'
" Hides "Press ? for help"
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
"Plug 'vim-airline/vim-airline'
"Plug 'vim-airline/vim-airline-themes'
"let g:airline_highlighting_cache = 1
"let g:airline#extensions#tabline#enabled = 1
" Aesthetics
Plug 'flazz/vim-colorschemes'
Plug 'croaker/mustang-vim'
Plug 'tiagofumo/vim-nerdtree-syntax-highlight'
Plug 'ryanoasis/vim-devicons'
Plug 'romainl/flattened'
Plug 'rakr/vim-one'
" Searching
Plug 'mileszs/ack.vim'
" Close delimiters
Plug 'Raimondi/delimitMate'
let delimitMate_matchpairs = "{:},(:)"
"let delimitMate_quotes = "\" `"
" Style
"Plug 'amperser/proselint', {'rtp': 'plugins/vim/syntastic_proselint/'}
"Plug 'scrooloose/syntastic'
"let g:syntastic_markdown_checkers = ['proselint']
"set statusline+=%#warningmsg#
"set statusline+=%{SyntasticStatuslineFlag()}
"set statusline+=%*
"let g:syntastic_always_populate_loc_list = 1
"let g:syntastic_auto_loc_list = 1
"let g:syntastic_check_on_open = 0
"let g:syntastic_check_on_wq = 0
"let g:syntastic_mode_map = { 'mode': 'passive', 'active_filetypes': [],'passive_filetypes': [] }
"Plug 'NLKNguyen/papercolor-theme'
Plug 'folke/tokyonight.nvim'
call plug#end()
" }}}
" {{{ Keyboard Shortcuts
" {{{ Remaps
let mapleader=","
"command! W w
"command! Wq wq
"command! Q q
"command! Qa qa
"command! Wqa wqa
nnoremap <CR> :noh<CR><CR>
noremap <silent> <Leader>n :NERDTreeToggle<CR>
nnoremap <Leader>c :let &cole=(&cole == 2) ? 0 : 2 <bar> echo 'conceallevel ' . &cole <CR>
"nnoremap <silent> [[ ?^\#<CR>
nnoremap <silent> [[ ?^\:\:\:{<CR>
"nnoremap <silent> ]] /^\#<CR>
nnoremap <silent> ]] /^\:\:\:{<CR>
nmap <silent> <leader>p :call PasteImage()<CR>
" Use arrow keys in wldmenu.
cnoremap <expr> <up> wildmenumode() ? "\<left>" : "\<up>"
cnoremap <expr> <down> wildmenumode() ? "\<right>" : "\<down>"
cnoremap <expr> <left> wildmenumode() ? "\<up>" : "\<left>"
cnoremap <expr> <right> wildmenumode() ? " \<bs>\<C-Z>" : "\<right>"
" Disable Ex mode
map q: <Nop>
nnoremap Q <nop>
" Ctrl-Space in any mode to save
nnoremap <c-space> :w<CR>o
inoremap <c-space> <Esc>:w<CR>o
" Save every time a new line is put in
"inoremap <CR> <CR><Esc>:wa<CR>i
nnoremap ZZ :wqa<CR>
nnoremap <C-p> :GitFiles<Cr>
" Provided by fzf
nnoremap <C-f> :Ag<Cr>
if executable('ag')
let $FZF_DEFAULT_COMMAND = 'ag -g ""'
endif
nnoremap <silent> <Leader>f :Ag <C-R><C-W><CR>
command W write
" }}}
" {{{ Leader Shortcuts
"
" Insert new lines in normal mode
nnoremap <Leader>o o<Esc>
nnoremap <Leader>O O<Esc>
" Write/quit in normal mode
nnoremap <Leader>w :w<CR>
nmap <Leader>ll :let @+=expand("%:p")<CR><CR>
nnoremap <silent> <leader>zj :call NextClosedFold('j')<cr>
nnoremap <silent> <leader>zk :call NextClosedFold('k')<cr>
nnoremap <silent> <Leader>lp :call StartPreview(1)<CR>
nnoremap <silent> <Leader>lpp :call StartPreview(2)<CR>
nnoremap <silent> <Leader>lo :call StartPreview(3)<CR>
nmap <silent> <leader>i :call CreateInkscape()<CR>
" Replace inline math $......$ with
" \[
" ......
" .\]
nnoremap <silent> <Leader>gs F$xvt$"+dxi\[<cr><cr>.\]<Esc>k"+P
"nnoremap <silent> <Leader>gs F$lvt$"+dxF$xwi<cr><cr><Esc>ki\[<cr><esc>"+po.\]
" Replace inline math $......$ with \( ...... \)
nnoremap <silent> <Leader>gb F$xvt$"+dxi\( \)<Esc>hh"+P
" Replace displaymath $$......$$ with displaymath \[ ...... \]
nnoremap <silent> <Leader>ga /\$\$<cr>Nxxwvnk$"+dknxxi\[<esc>"+p<esc>o.\]<esc>
" }}}
" {{{ Folds
" Jump to previous/next fold
function! NextClosedFold(dir)
let cmd = 'norm!z' . a:dir
let view = winsaveview()
let [l0, l, open] = [0, view.lnum, 1]
while l != l0 && open
exe cmd
let [l0, l] = [l, line('.')]
let open = foldclosed(l) < 0
endwhile
if open
call winrestview(view)
endif
endfunction
" }}}
"
" {{{ Terminal buffers
" Escape terminal
tnoremap <Esc> <C-\><C-n>
tnoremap <M-[> <Esc>
tnoremap <C-v><Esc> <Esc>
" }}}
" }}}
" {{{ Specific Filetype Commands
autocmd Filetype tmux setlocal foldmethod=marker
" }}}
" {{{ Default window settings when opening a new file.
function s:markdownSetup()
" Open panes
let s:current_win = winnr()
" Open Nerdtree and hide it
"NERDTree | wincmd p | NERDTreeFind | wincmd p | NERDTreeToggle
" Open Voom and split Nerdtree above it
Voom pandoc
"sbuffer NERD_tree_1 |
"execute bufwinnr(s:current_win) . 'wincmd w'
" Close Nerdtree if last buffer open
"autocmd BufWinEnter,WinEnter term://* if winnr("$") <= 3 | qa | endif
"autocmd BufWinEnter,WinEnter NERD_tree* if winnr("$") <= 2 | qa | endif
"autocmd BufWinEnter,WinEnter *VOOM* if winnr("$") <= 2 | qa | endif
" Remap write/quit to close all terminals, nerdtree, voom, etc
cnoreabbrev q q
cnoreabbrev w wa
cnoreabbrev wq wq
call s:pandocSyntax()
call FixResizing()
endfunction
" }}}
" {{{ Pandoc PDF and HTML preview
function! FixResizing()
echo "Fixing resize"
let windowNr = bufwinnr("term")
if windowNr > 0
execute windowNr 'wincmd w'
resize 5
wincmd p
redraw
endif
endfunction
let g:previews_open = 0
function! StartPreview(preview_type)
belowright split
resize 5
if a:preview_type == 1
term vimpreview.sh -f "%:p" -v
let g:previews_open = 1
elseif a:preview_type == 2
term vimpreview.sh -f "%:p"
let g:previews_open = 1
elseif a:preview_type == 3
term pdfpreview.sh -f "%:p" -v
let g:previews_open = 2
endif
execute "normal! G"
wincmd p
endfunction
autocmd VimResized * call FixResizing()
function! KillPreviews()
if g:previews_open == 1
" silent exec "!pkill qutebrowser"
elseif g:previews_open == 2
silent exec "!pkill zathura"
endif
endfunction
autocmd VimLeave *.md call KillPreviews()
" }}}
" {{{ Automatically start preview?
"autocmd VimEnter */section* call StartPreview(1)
"autocmd CursorHold,CursorHoldI *.md update
"set updatetime=300
" }}}
" {{{ Custom Pandoc Syntax and Conceals
function s:pandocSyntax()
set filetype=markdown.pandoc
setlocal spell
" Extra Syntax
syntax match DZGConceal /:::/ conceal cchar=―
syntax match DZGConceal /\\hfill/ conceal cchar=―
" Theorem Environments
syn region DZGEnvironments start="{." end="}" transparent contains=DZGMathResults,DZGMathThms,DZGMathNames
syn keyword DZGMathResults contained proposition corollary example problem solution question remark warnings exercise slogan
hi def link DZGMathResults Statement
syn keyword DZGMathThms contained theorem definition proof
hi def link DZGMathThms Special
syntax match DZGMathNames /title=/ contained conceal cchar=
"source /home/zack/dotfiles/vim/tex_conceal.vim
endfunction
au VimEnter *.md call s:markdownSetup()
au BufNewFile,BufFilePre,BufRead *.md call s:pandocSyntax()
" Add conceals to Voom pane
au FileType voomtree syntax match someCustomes /\$\\work\$/ conceal cchar=🚩
au FileType voomtree syntax match someCustomes /\$\\done\$/ conceal cchar=✨
" }}}
function! PasteImage()
let this_file_dir = expand("%:p:h")
let s = substitute(system("date '+%Y-%m-%d_%H-%M-%S' "), '\n\+$', '', '')
"let mime_check = system("xclip -selection clip -t TARGETS -o | grep png")
"if mime_check =~ "png"
let t = system("mkdir -p '".this_file_dir."/figures' && wl-paste > '".this_file_dir."/figures/".s.".png'")
echo t
let md_text = "![](figures/" . s . ".png)"
execute "normal! o".md_text
"else
"echo "Clipboard doesn't contain an image."
"endif
endfunction
function! PasteQuiverDiagram()
normal "+pdd/endopdwi> [Link to Diagram](A):w
endfunction
nmap <silent> <leader>qp :call PasteQuiverDiagram()<CR>
function! ZoteroCite()
" pick a format based on the filetype (customize at will)
let format = &filetype =~ '.*tex' ? 'citep' : 'pandoc'
let api_call = 'http://127.0.0.1:23119/better-bibtex/cayw?format=cite&brackets=1'
let ref = system('curl -s '.shellescape(api_call))
return ref
endfunction
noremap <leader>z "=ZoteroCite()<CR>p
inoremap <C-z> <C-r>=ZoteroCite()<CR>
inoremap <expr> <c-x><c-m> fzf#vim#complete("find_all_latex_labels.sh")
" {{{ Aesthetics
set t_Co=256
colorscheme tokyonight-moon
" Use spaces instead of tabs (necessary for haskell/ghc)
set tabstop=2 " Inserts 2 spaces when tab key is pressed.
set softtabstop=2 " Deletes 2 spaces (simulates deleting a tab)
set shiftwidth=2 " Inserts 2 spaces for auto-indentation.
set expandtab " Insert spaces whenever tab key is pressed.
set shiftround " Round indent to nearest 'shiftwidth' multiple
syntax on
" Numbered lines
set number
" Actual line number on current line, otherwise relative line numbers above
" and below
set relativenumber
" Concleas
set conceallevel=1
" ? I forget
"set title
"set titlestring=%{hostname()}\ \ %F\ \ %{strftime('%Y-%m-%d\ %H:%M',getftime(expand('%')))}
" Highlight current line.
set cursorline
autocmd BufEnter * setlocal cursorline
autocmd BufEnter * :hi CursorLine cterm=NONE ctermbg=239 ctermfg=NONE
hi NonText ctermbg=none
hi Normal guibg=NONE ctermbg=NONE
hi clear Conceal
" Always center cursorline
set scrolloff=999
autocmd BufNewFile,BufRead *.tikz set syntax=tex
" {{{ Folding
let g:markdown_folding = 1
set foldcolumn=3
set foldlevel=2
augroup remember_folds
autocmd!
autocmd BufWinLeave *.md mkview
autocmd BufWinEnter *.md silent! loadview
augroup END
" }}}
" }}}
" {{{ Low-Level Vim Functionality
set nobackup " Turn backup off (store everything in version control)
set nowb
set noswapfile
set mouse=a " Allow mouse selection
set encoding=utf-8
let &termencoding=&encoding
" {{{ Persistent Undo
let s:undoDir = "/tmp/.undodir_" . $USER
if !isdirectory(s:undoDir)
call mkdir(s:undoDir, "", 0700)
endif
let &undodir=s:undoDir
set undofile
" }}}
" {{{ Return to last edit position when opening files
augroup last_edit
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
" }}}
" {{{ Run command line jobs (!somescript) async?
command! -nargs=1 -complete=file
\ StartAsync call jobstart(expand(<f-args>), {
\ 'on_exit': { j,d,e ->
\ execute('echom "['.<f-args>.'] command finished with exit status '.d.'"', '')
\ }
\ })
" }}}
" }}}
" {{{ Prose Functionality
" {{{ Spellcheck
" No spellchecking fullstops without capitalization
set spellcapcheck=
set ignorecase
set smartcase
" }}}
" }}}
" {{{ Abbreviations
iabbrev impies implies
iabbrev keq leq
iabbrev suchtat suchthat
iabbrev pver over
iabbrev Rouche Rouché
iabbrev rouche rouché
iabbrev defineas definedas
iabbrev subet subset
iabbrev Etale Étale
iabbrev etale étale
iabbrev kapp kappa
iabbrev apha alpha
iabbrev variabel variable
iabbrev interset intersect
iabbrev lmabda lambda
iabbrev Wely Weyl
iabbrev rhi phi
iabbrev lamda lambda
iabbrev tp to
iabbrev Cech Čech
iabbrev corss cross
iabbrev Neron Néron
iabbrev abelain abelian
iabbrev noetherian Noetherian
iabbrev artinian Artinian
iabbrev poincare Poincaré
iabbrev Poincare Poincaré
iabbrev kahler kähler
iabbrev Kahler Kähler
iabbrev char ch
iabbrev detla delta
iabbrev Detla Delta
" }}}
" Quit is only Nerdtree + one other pane is open?
" autocmd bufenter * if (winnr("$") == 2 && exists("b:NER3Tree") && b:NERDTree.isTabTree()) | qa | endif
autocmd Filetype markdown.pandoc let g:enable_quicktex = 1
" See `~/.config/nvim/after/ftplugin/pandoc/quicktex_dict.vim`
" {{{ Custom Functions
" {{{ Converting Math
function ConvertOldMath()
" Save cursor position
let l:save = winsaveview()
" Remove trailing whitespace
%s/\\definedas/\\da/g
%s/\\begin{align\*}/\\[/g
%s/\\end{align\*}/\\]/g
%s/\\begin{center}//g
%s/\\end{center}//g
"%s/X\/k/X_{\/k}/g
%s/\(\a\{1}\)\/\([kKS]\)/\1_{\/\2}/g
%s/\(\a\{1}\)\/\(\\ell\)/\1_{\/\2}/g
%s/\(\a\+\)_\(\w\+\)/\1_{\2}/g
%s/\\red/\\mathrm{red}/g
%s/\\def/\\mathrm{def}/g
%s/\\obs/\\mathrm{obs}/g
%s/\\directlimit/\\directlim/g
" Move cursor to original position
call winrestview(l:save)
echo "Converted math"
endfunction
" }}}
" {{{ Inkscape and Xournal handling
function CreateInkscape()
let s:fig_dir = getcwd() . "/figures"
silent exec '!mkdir -p "' . s:fig_dir . '"'
let s:outfile= system('inkscape-figures.sh -d"' . s:fig_dir. '"')
if v:shell_error == 1
echo "Error: \n" . s:outfile
else
echo s:outfile
exe "normal! a" . s:outfile . "\<Esc>"
endif
endfunction
" }}}
function! SyntaxItem()
return synIDattr(synID(line("."),col("."),1),"name")
endfunction
set statusline+=%{SyntaxItem()}
map <F6> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
autocmd QuitPre * call <sid>TermForceCloseAll()
function! s:TermForceCloseAll() abort
let term_bufs = filter(range(1, bufnr('$')), 'getbufvar(v:val, "&buftype") == "terminal"')
for t in term_bufs
execute "bd! " t
endfor
endfunction
" }}}
" {{{ Notes
"autocmd BufWritePost *note-*.md silent !buildNote.sh %:p
" Fix resize issue on open
autocmd VimEnter * :silent exec "!kill -s SIGWINCH $PPID"
" }}}
set background=light
setlocal conceallevel=2
hi clear conceal