-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
561 lines (479 loc) · 20 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
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
" Configuration file for vim
" Author: Kit La Touche <kit@transneptune.net>
" Date: 2023-01-13
" Comment: Vim on and love through unrepining hours
" Before us lies eternity; our souls
" Are vim, and a continual farewell.
" First, we don't care about vi compatability.
set nocompatible
" Need to turn filetype off when starting Vundle
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
" Functionality
Plugin 'airblade/vim-gitgutter' " Show git add/delete/change per line in gutter.
Plugin 'ctrlpvim/ctrlp.vim' " Best way to open files.
Plugin 'ervandew/supertab' " Generic tab completion.
Plugin 'flazz/vim-colorschemes' " Provides the hybrid color scheme I like.
Plugin 'jeetsukumaran/vim-buffergator' " Better management of buffers.
Plugin 'python-mode/python-mode' " Excellent Python language support.
" Plugin 'ycm-core/YouCompleteMe' " Powerful autocomplete tools, but they keep breaking
Plugin 'powerline/powerline', {'rtp': 'powerline/bindings/vim/'}
" ^^ Better vim status bar.
Plugin 'preservim/tagbar' " Show file logical structure.
Plugin 'MattesGroeger/vim-bookmarks' " Improve line marks.
Plugin 'sjl/gundo.vim' " More powerful navigation of the undo tree.
Plugin 'tpope/vim-dispatch' " Better :make commands
Plugin 'tpope/vim-commentary' " Adds comments as text objects.
Plugin 'tpope/vim-fugitive' " Git integration tools.
Plugin 'tpope/vim-obsession' " Save and restore vim sessions easily.
Plugin 'tpope/vim-repeat' " Repeat some more complex actions than basic vim.
Plugin 'tpope/vim-surround' " Manage surrounding quotes, parens, brackets, and braces.
Plugin 'tpope/tpope-vim-abolish' " Better smarter replacing.
Plugin 'wlonk/argtextobj.vim' " Adds function arguments as text objects. (Using my own fork.)
Plugin 'godlygeek/tabular' " Automatic formatting of Markdown tables.
Plugin 'plasticboy/vim-markdown' " Markdown syntax and tools. MUST come after tabular.
" Syntaxes
Plugin 'Glench/Vim-Jinja2-Syntax' " Jinja2 and Nunjucks syntax
Plugin 'Rykka/riv.vim' " reStructuredText tools
Plugin 'cespare/vim-toml' " TOML syntax, for Rust and Python packaging
Plugin 'hashivim/vim-terraform' " Terraform syntax
Plugin 'leafgarland/typescript-vim' " TypeScript syntax
Plugin 'mxw/vim-jsx' " React and JSX
Plugin 'pangloss/vim-javascript' " JavaScript syntax and tools
Plugin 'posva/vim-vue' " Vue syntax
Plugin 'rust-lang/rust.vim' " Rust syntax and tools
Plugin 'delphinus/vim-firestore' " Firestore rules
Plugin 'mustache/vim-mustache-handlebars' " Handlebars syntax and tools.
" Prose writing
Plugin 'junegunn/limelight.vim' " Highlights the current paragraph and dims the rest.
Plugin 'junegunn/goyo.vim' " Distraction-free writing.
" External Utilities
Plugin 'wlonk/vim-tmuxify' " My fork to control Tmux panes from Vim.
" Plugins for syntaxes I don't currently work with:
" Plugin 'digitaltoad/vim-pug' " Syntax highlighting for the Pug templating language.
" Plugin 'lervag/vimtex' " LaTeX
" Plugin 'wlonk/choicescript.vim' " Choicescript syntax and tools.
" Plugins I never folded into my workflow:
" Plugin 'alfredodeza/pytest.vim' " Integration with py.test
" Plugin 'alvan/vim-closetag' " If I open an HTML tag, I want to close it, alright?
" Plugin 'christoomey/vim-sort-motion' " Sort text objects.
" Plugin 'jmcomets/vim-pony' " Utilities for working with Django projects.
" Plugin 'mattn/emmet-vim' " More better HTML writing
" Plugin 'michaeljsmith/vim-indent-object' " Add indent objects.
" Plugin 'mileszs/ack.vim' " Search all files in a codebase efficiently.
" Plugin 'racer-rust/vim-racer' " Auto completion for Rust.
" Plugin 'rizzatti/dash.vim' " Dash integration (OS X only).
call vundle#end()
" Turn filetype back on now that Vundle is done
filetype plugin indent on
" Brief help for Vundle
" :PluginList - list configured plugins
" :PluginInstall(!) - install (update) plugins
" :PluginSearch(!) foo - search (or refresh cache first) for foo
" :PluginClean(!) - confirm (or auto-approve) removal of unused plugins
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" ==============================================================================
""""
" First, some basics:
syntax on " Enable synax highlighting.
colorscheme gruvbox " A color scheme I like.
set autoindent " Smart indent on newline.
set backspace=2 " More powerful backspace (works on space-tabs).
set clipboard=unnamed " Default to system clipboard.
set encoding=utf-8 " A more elegant encoding for a more civilized age.
set expandtab " Turn tabs into spaces.
set fileencoding=utf-8 " A more elegant encoding for a more civilized age.
set foldlevelstart=20 " Start with things unfolded by default.
set hidden " Allow hiding buffers without saving all changes.
set hlsearch " Highlight search matches.
set laststatus=2 " Make the status bar show a bit less.
set lazyredraw " Only redraw when you have to (helps with flickering).
set noshowmode " Don't need to show mode, we have POWERLINE.
set noswapfile " Don't write those pesky .*.swp files.
set number " Show linenumbers in leftmost column.
set pastetoggle=<F2> " Use F2 to toggle paste mode.
set shiftwidth=4 " By default, make tabs 4 spaces.
set shortmess=aIO " Configure status-line messages:
" - a: use shorter versions of all basic messages, to
" conserve screen real estate.
" - I: Don't show the "this is vim" intro message on
" startup.
" - O: Overwrite previous messages when reading a file.
set showtabline=2 " Show all open tabs at the top, always.
set softtabstop=4 " Again, tabs are 4 spaces.
set splitbelow " Open splits below current window.
set splitright " Open vsplits to right of current window.
set switchbuf="usetab" " When jumping to a buffer, use the existing buffer and
" tab, if available.
set tabstop=4 " Tabs. Are. Four. Spaces.
set ttyfast " Convince vim it has a fast connection to the TTY.
" Let's see the line we're on
set cursorline
highlight CursorLine term=bold cterm=bold guibg=Grey40
highlight Comment cterm=italic
" Let's configure limelight to dim inactive paragraphs:
let g:limelight_conceal_ctermfg = 240
"""
augroup vimrcEx
" Clear all autocmds in the group
autocmd!
" Jump to last cursor position unless it's invalid or in an event handler
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
autocmd BufReadPost COMMIT_EDITMSG
\ exe "normal! gg0"
autocmd BufReadPost PULLREQ_EDITMSG
\ exe "normal! gg0"
autocmd BufReadPost GHI_ISSUE
\ exe "normal! gg0"
augroup END
"""
" Tagbar configuration
nmap <F8> :TagbarToggle<CR>
let g:tagbar_type_rst = {
\ 'ctagstype': 'rst',
\ 'ctagsargs' : '-f - --sort=no',
\ 'kinds' : [
\ 'c:chapter',
\ 's:sections',
\ 'S:subsections',
\ 'i:images'
\ ],
\ 'sro' : '|',
\ 'kind2scope' : {
\ 'c' : 'chapter',
\ 's' : 'section',
\ 'S' : 'subsection',
\ },
\ 'sort': 0,
\ }
let g:tagbar_type_rust = {
\ 'ctagstype' : 'rust',
\ 'kinds' : [
\ 'T:types,type definitions',
\ 'f:functions,function definitions',
\ 'g:enum,enumeration names',
\ 's:structure names',
\ 'm:modules,module names',
\ 'c:consts,static constants',
\ 't:traits',
\ 'i:impls,trait implementations',
\ ]
\ }
""""
" Quickfix controls
augroup vimrcQuickfix
autocmd BufReadPost quickfix nnoremap <buffer> <cr> <cr>
augroup END
""""
" Python configuration
augroup vimrcPython
autocmd!
autocmd FileType python highlight Excess ctermbg=DarkGrey guibg=Black
" Use a width of 88. This isn't in line with PEP8, but it's in line with
" Black, and I somewhat prefer it:
autocmd FileType python match Excess /\%88v.*/
autocmd FileType python setlocal textwidth=88
autocmd FileType python set nowrap
autocmd FileType python nnoremap <leader>= :0,$!yapf<cr>
autocmd FileType python nnoremap <leader>i :!isort -ns %:t %<cr><cr>
" .pyi is a Python interface file.
autocmd BufNewFile,BufRead *.pyi set filetype=python
augroup END
""""
" Sphinx & reStructuredText configuration
augroup vimrcSphinx
autocmd!
autocmd BufEnter *.rst silent! lcd %:p:h
autocmd FileType rst nnoremap <cr> :Dispatch make dirhtml<cr>
autocmd FileType rst setlocal textwidth=72
augroup END
""""
" Jinja and Nunjucks config
autocmd BufNewFile,BufRead *.njk set filetype=jinja
""""
" Django templating language
autocmd BufNewFile,BufRead *.html set filetype=htmldjango
autocmd FileType htmldjango inoremap {% {% %}<left><left><left>
autocmd FileType htmldjango inoremap {{ {{ }}<left><left><left>
augroup vimrcDjango
autocmd!
autocmd FileType htmldjango let b:surround_{char2nr("v")} = "{{ \r }}"
autocmd FileType htmldjango let b:surround_{char2nr("{")} = "{{ \r }}"
autocmd FileType htmldjango let b:surround_{char2nr("%")} = "{% \r %}"
autocmd FileType htmldjango let b:surround_{char2nr("b")} = "{% block \1block name: \1 %}\r{% endblock \1\1 %}"
autocmd FileType htmldjango let b:surround_{char2nr("i")} = "{% if \1condition: \1 %}\r{% endif %}"
autocmd FileType htmldjango let b:surround_{char2nr("w")} = "{% with \1with: \1 %}\r{% endwith %}"
autocmd FileType htmldjango let b:surround_{char2nr("f")} = "{% for \1for loop: \1 %}\r{% endfor %}"
autocmd FileType htmldjango let b:surround_{char2nr("c")} = "{% comment %}\r{% endcomment %}"
augroup END
""""
" Markdown configuration
let g:vim_markdown_folding_style_pythonic = 1
" Spell check markdown files.
autocmd FileType markdown setlocal spell
autocmd FileType rst setlocal spell
""""
" Handlebars abbreviations
" {{# etc.
let g:mustache_abbreviations = 1
""""
" Narrower indents
" (These don't have to be in an augroup, as repeating them has no effect.)
autocmd FileType css setlocal shiftwidth=2 tabstop=2
autocmd FileType eruby setlocal shiftwidth=2 tabstop=2
autocmd FileType handlebars.html setlocal shiftwidth=2 tabstop=2
autocmd FileType html setlocal shiftwidth=2 tabstop=2
autocmd FileType html.handlebars setlocal shiftwidth=2 tabstop=2
autocmd FileType htmldjango setlocal shiftwidth=2 tabstop=2
autocmd FileType jade setlocal shiftwidth=2 tabstop=2
autocmd FileType javascript setlocal shiftwidth=2 tabstop=2
autocmd FileType javascript.jsx setlocal shiftwidth=2 tabstop=2
autocmd FileType less setlocal shiftwidth=2 tabstop=2
autocmd FileType pug setlocal shiftwidth=2 tabstop=2
autocmd FileType ruby setlocal shiftwidth=2 tabstop=2
autocmd FileType sass setlocal shiftwidth=2 tabstop=2
autocmd FileType scss setlocal shiftwidth=2 tabstop=2
autocmd FileType typescript setlocal shiftwidth=2 tabstop=2
autocmd FileType typescriptreact setlocal shiftwidth=2 tabstop=2
autocmd FileType vue setlocal shiftwidth=2 tabstop=2
autocmd FileType yaml setlocal shiftwidth=2 tabstop=2
autocmd FileType rst setlocal shiftwidth=3 tabstop=3
""" Basics:
" No arrow keys
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
" Let's get fancy. Change two fundamental mappings
let mapleader=","
nnoremap ; :
vnoremap ; :
cnoremap <expr> %% expand('%:h').'/'
""""
" ack.vim searching
" If we have ag (the Silver Searcher), let's use it.
if executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
""""
" Pymode
" Documentation
let g:pymode_doc = 1
let g:pymode_doc_key = 'K'
" Linting
let g:pymode_lint = 0
let g:pymode_lint_checkers = ['flake8']
let g:pymode_lint_ignore = ["W503"]
" Auto check on save
let g:pymode_lint_write = 1
" Support virtualenv
let g:pymode_virtualenv = 1
" Enable breakpoints plugin
let g:pymode_breakpoint = 1
let g:pymode_breakpoint_key = '<leader>b'
" syntax highlighting
let g:pymode_python = 'python3'
let g:pymode_syntax = 1
let g:pymode_syntax_all = 1
let g:pymode_syntax_indent_errors = g:pymode_syntax_all
let g:pymode_syntax_space_errors = g:pymode_syntax_all
" Don't use pymode's folding, it's slow af:
let g:pymode_folding = 0
" Let's use Jedi instead of Rope, but turn off the documentation window.
let g:pymode_rope = 0
autocmd FileType python setlocal completeopt-=preview
let g:ycm_python_binary_path = 'python'
" When I Goyo, I should also Limelight:
autocmd! User GoyoEnter Limelight
autocmd! User GoyoLeave Limelight!
" Turn off ycm diagnostics, so we can use leader-d for 'definition':
" let g:ycm_key_detailed_diagnostics = ''
" nmap <leader>d :YcmCompleter GoTo<cr>
" Custom Python helpers:
" Insert argskwargs with <c-l>
imap <c-l> *args,<space>**kwargs
imap <c-l><c-t> *args:<space>VarArg,<space>**kwargs:<space>KwArg
""""
" Ctrl-P (Better file opening)
" With Buffergator, to better handle buffer-switching
" Setup some default ignores
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](\.(git|hg|svn|tox)|tmp|node_modules|bower_components|dist|\_site|*.egg-info|htmlcov|jscov|_?build)$',
\ 'file': '\v\.(exe|so|dll|class|png|jpg|jpeg|pyc|swp)$',
\}
" Use the nearest .git directory as the cwd
" This makes a lot of sense if you are working on a project that is in
" version control. It also supports works with .svn, .hg, .bzr.
let g:ctrlp_working_path_mode = 'r'
""""
" Buffergator
" Use the right side of the screen
let g:buffergator_viewport_split_policy = 'R'
" I want my own keymappings...
let g:buffergator_suppress_keymaps = 1
""""
" Rust settings
let g:racer_cmd = $HOME . "/.cargo/bin/racer"
let $RUST_SRC_PATH = $HOME . "/code/rust"
augroup vimrcRust
autocmd FileType rust :compiler cargo
autocmd FileType rust nnoremap <cr> :Make test<cr>
augroup END
"""" Mappings
" Convert to snake_case:
nmap <silent><leader>sc :s#\C\(\<\u[a-z0-9]\+\|[a-z0-9]\+\)\(\u\)#\l\1_\l\2#g<cr>
" Select last pasted lines
nnoremap gp `[v`]
" Better paragraph wrapping.
vmap Q gq
nmap Q gqap
" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Show gundo
nnoremap <F5> :GundoToggle<cr>
" edit vimrc/zshrc and load vimrc bindings
nnoremap <leader>ev :vsp $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
" Clear last-search buffer
nnoremap <space> :nohlsearch<cr>
" Go to the previous buffer open
nmap <silent><leader>jj :BuffergatorMruCyclePrev<cr>
" Go to the next buffer open
nmap <silent><leader>kk :BuffergatorMruCycleNext<cr>
" View the entire list of buffers open
nmap <silent><leader>bl :BuffergatorOpen<cr>
" New tab, close tab kind of behavior.
nmap <silent><leader>T :enew<cr>
nmap <silent><leader>bq :bp <bar> bd #<cr>
" Quick switch last two buffers
nmap <silent><leader><leader> <C-^>
" Run tests
" (May want to generalize or improve this eventually?)
nmap <silent><leader>t <Esc>:Pytest file<cr>
" Set filetype
nmap <leader>ft <Esc>:set ft=
" Open sibling file
nmap <leader>os <Esc>:e %:h/
" Custom vim-tmuxify actions for particular filetypes:
if !exists('g:tmuxify_run')
let g:tmuxify_run = {}
endif
let g:tmuxify_run['rust'] = "cargo test"
function! GetTxWindow()
let win = system('tmux display-message -p ' . shellescape("'#I'"))
let win = substitute(win, '\n$', '', '')
let win = substitute(win, "'", '', 'g')
return win
endfunction
function! SetGlobalTxPane()
let pane = "0:" . GetTxWindow() . ".2"
execute ':TxSetPane! ' . pane
endfunction
function! SetTestCmd(cmd)
call SetGlobalTxPane()
echo a:cmd
" By sending SIGINT first, we bump the pane down to the latest prompt.
" This avoids vim-tmuxify asking us if we really wanna scroll down. As we
" frequently have to scroll up to see the stacktrace of a failing test,
" this saves us a lot of grief.
execute ":nmap <leader><cr> :TxUncopy! \\| TxSend! " . a:cmd . "<cr>"
endfunction
command! -nargs=1 SetTestCmd call SetTestCmd(<f-args>)
""""
" Custom functions
" Don't get me wrong, I love smart quotes, but not in source.
function! RemoveFancyCharacters()
let typo = {}
let typo["“"] = '"'
let typo["”"] = '"'
let typo["‘"] = "'"
let typo["’"] = "'"
let typo["–"] = '--'
let typo["—"] = '---'
let typo["…"] = '...'
:exe ":%s/".join(keys(typo), '\|').'/\=typo[submatch(0)]/ge'
endfunction
command! RemoveFancyCharacters :call RemoveFancyCharacters()
" Create missing directories on write. Really shines in combo with the
" auto-test-files function below.
function s:MkNonExDir(file, buf)
if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
let dir=fnamemodify(a:file, ':h')
if !isdirectory(dir)
call mkdir(dir, 'p')
endif
endif
endfunction
augroup vimrcCreateDir
autocmd!
autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
augroup END
" Rename current file
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'))
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
endif
endfunction
map <leader>n :call RenameFile()<cr>
" Git checkpoint
function! GitCheckpoint()
" Requires the git-checkpoint command defined in .gitconfig
silent !git checkpoint
redraw!
endfunction
map <silent><leader>gc :call GitCheckpoint()<cr>
" OS X only: copy a markdown buffer to the system clipboard as richtext.
function! CopyMarkdownAsRichText()
let markdown = 'kramdown'
exec ':w !' . markdown .
\ '| textutil -stdin -inputencoding utf-8 -format html -convert rtf -stdout ' .
\ '| pbcopy'
endfunction
nmap <silent><leader>mkc :call CopyMarkdownAsRichText()<cr>
" Increment a column of numbers, one after the other.
function! Incr()
let a = line('.') - line("'<")
let c = virtcol("'<")
if a > 0
execute 'normal! '.c.'|'.a."\<C-a>"
endif
normal `<
endfunction
vnoremap <C-i> :call Incr()<CR>
" If we're in a Python file 'foo.py', open 'tests/foo.py'
function RelatedTests()
let current_file = expand("%")
let path_components = split(current_file, '/')
let is_python = match(current_file, '.py$') != -1
let in_tests = match(current_file[-2], '^tests$') != -1
if !is_python || in_tests
return 'no tests'
end
" let tests_path = path_components[:-2] + ['tests'] + path_components[-1:]
let tests_path = path_components[:-2] + ['tests'] + ['test_' . join(path_components[-1:], '')]
return join(tests_path, '/')
endfunction
function OpenRelatedTests()
let related_tests = RelatedTests()
if related_tests != ''
exec ':e ' . related_tests
end
endfunction
nnoremap <leader>. :call OpenRelatedTests()<cr>
function Blacken()
exec '%! black -q -'
endfunction
command! Blacken call Blacken()