-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
530 lines (432 loc) · 16 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
set nocompatible " be iMproved, required
filetype off " required
""""""""""""""""""""""""""""""""""""""""
" Vundle plugins
""""""""""""""""""""""""""""""""""""""""
" set the runtime path to include Vundle and initialize
set rtp+=~/.jvim/bundle/vundle
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'arcticicestudio/nord-vim'
Plugin 'scrooloose/nerdtree'
Plugin 'tpope/vim-surround'
Plugin 'spf13/vim-autoclose'
Plugin 'godlygeek/tabular'
Plugin 'mattn/emmet-vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'easymotion/vim-easymotion'
Plugin 'editorconfig/editorconfig-vim'
Plugin 'bling/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'xolox/vim-misc'
Plugin 'terryma/vim-expand-region'
Plugin 'w0rp/ale'
Plugin 'sheerun/vim-polyglot'
Plugin 'vimwiki/vimwiki'
Plugin 'scrooloose/nerdcommenter'
Plugin 'junegunn/goyo.vim'
Plugin 'sotte/presenting.vim'
Plugin 'bccalc.vim'
Plugin 'vim-scripts/DrawIt'
" fzf
Plugin 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --bin' }
Plugin 'junegunn/fzf.vim'
" end fzf
" snipmate
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
" end snipmate
" All plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
""""""""""""""""""""""""""""""""""""""""
" Colors
""""""""""""""""""""""""""""""""""""""""
colorscheme nord
syntax on
highlight clear SignColumn
highlight GitGutterAdd ctermfg=2 ctermbg=None
highlight GitGutterChange ctermfg=3 ctermbg=None
highlight GitGutterDelete ctermfg=1 ctermbg=None
highlight GitGutterChangeDelete ctermfg=3 ctermbg=None
" Don't highlight special characters such as tabs and whitespace at EOL
highlight SpecialKey ctermbg=None
set termguicolors
""""""""""""""""""""""""""""""""""""""""
" General Settings
""""""""""""""""""""""""""""""""""""""""
let mapleader = ' '
set clipboard=unnamed " Wire up clipboard
set cursorline " Show line
set backspace=indent,eol,start " Backspace for dummies
set linespace=0 " No extra spaces between rows
set nu " Line numbers on
set showmatch " Show matching brackets/parenthesis
set incsearch " Find as you type search
set hlsearch " Highlight search terms
set winminheight=0 " Windows can be 0 line high
set ignorecase " Case insensitive search
set smartcase " Case sensitive when uc present
set wildmenu " Show list instead of just completing
set wildmode=list:longest,full " Command <Tab> completion, list matches, then longest common part, then all.
set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too
set scrolljump=1 " Lines to scroll when cursor leaves screen
set scrolloff=3 " Minimum lines to keep above and below cursor
set foldenable " Auto fold code
set list
set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
set nowrap " Do not wrap long lines
set autoindent " Indent at the same level of the previous line
set shiftwidth=2 " Use indents of 4 spaces
set expandtab " Tabs are spaces, not tabs
set tabstop=2 " An indentation every four columns
set softtabstop=2 " Let backspace delete indent
set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
set splitright " Puts new vsplit windows to the right of the current
set splitbelow " Puts new split windows to the bottom of the current
set matchpairs+=<:> " Match, to be used with %
set pastetoggle=<F12> " pastetoggle (sane indentation on pastes)
set history=1000 " Store a ton of history (default is 20)
set nospell " Spell checking off be default
set cursorcolumn " Include a vertical line for your cursor
set backupdir=~/.vim/backup// " Clean backups that arent stored in your current dir
set directory=~/.vim/swp// " Clean swaps that arent stored in your current dir
set relativenumber " Enable relative line numbers be default
set mouse=a " Enable mouse support in all modes. Particularly useful to resize windows.
""""""""""""""""""""""""""""""""""""""""
" Hooks
""""""""""""""""""""""""""""""""""""""""
" Syntax highlighting based on file extensions
autocmd BufNewFile,BufRead *.md set filetype=markdown
autocmd BufNewFile,BufRead *.less set filetype=less
" Clean trailing whitespace
autocmd FileType c,cpp,java,go,php,javascript,python,twig,xml,yml autocmd BufWritePre <buffer> call StripTrailingWhitespace()
" Use absolute line number in insert mode
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
""""""""""""""""""""""""""""""""""""""""
" Custom mappings
""""""""""""""""""""""""""""""""""""""""
" Be consistent with C and D
nnoremap Y y$
" Find merge conflict markers
noremap <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR>
" Visual shifting (does not exit Visual mode)
vnoremap < <gv
vnoremap > >gv
" Allow using the repeat operator with a visual selection (!)
" http://stackoverflow.com/a/8064607/127816
vnoremap . :normal .<CR>
" Force write the file for when you forget to use sudo
cnoremap w!! w !sudo tee % >/dev/null
" Adjust viewports to the same size
nnoremap <Leader>= <C-w>=
" Easier pane/tab navigation
nnoremap <silent> <c-k> :wincmd k<CR>
nnoremap <silent> <c-j> :wincmd j<CR>
nnoremap <silent> <c-h> :wincmd h<CR>
nnoremap <silent> <c-l> :wincmd l<CR>
nnoremap <silent> <leader>m :wincmd R<CR>
nnoremap <silent> H :tabprev<CR>
nnoremap <silent> L :tabnext<CR>
" Easier pane resizing TODO: alt not working
nnoremap <silent> <A-h> <C-w><
nnoremap <silent> <A-j> <C-W>-
nnoremap <silent> <A-k> <C-W>+
nnoremap <silent> <A-l> <C-w>>
if has('nvim')
" Hack to get C-h working in NeoVim
nnoremap <BS> <C-W>h
endif
" Execute contents of current line
nnoremap <Leader>x :exec 'r! ' . getline('.')<CR>
nnoremap <Leader>xx :call ReplaceAndExecLine()<CR>
" Easier file formatting
nnoremap <Leader>f gg=G
" Find and replace word under cursor
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/
" Global search/replace for selection
vnoremap s "sy:%s/<C-R>"/
" Open file under cursor respecting :<line>:<col> if present
nnoremap <Leader>of gF
" Open in GitHub
nnoremap <leader>og :!echo `git-url`/blob/`git rev-parse HEAD`/<C-R>=expand('%')<CR>\#L<C-R>=line('.')<CR> \| xargs open<CR><CR>
" Make ' behave like ` for easier mark navigation
nnoremap ' `
" Makes * not jump to the next search item
" http://stackoverflow.com/a/4257175/895558
noremap * *``zz
" Fill the current line with dashes to 80 characters
noremap <Leader>- :call FillLine('-')<CR>
" Search for visual selection
vnoremap // y/<C-R>"<CR>
" Cause paste to behavior like a normal clipboard where the replaced contents
" are not added back into the register
vnoremap p "_dP
" Base64 decode
vnoremap <leader>64d c<c-r>=system('base64 --decode', @")<cr><esc>
vnoremap <leader>64e c<c-r>=system('base64', @")<cr><esc>
" Spelling
nnoremap <Leader>ts :set spell!<CR>
" Clear highlighting
nnoremap <Leader>n :noh<CR>
" Copy current location to clipboard
nnoremap <Leader>l :call system('pbcopy', @% . ":" . line('.'))<CR>
" Convert number under cursor to human readable"
nnoremap <Leader>b :call BytesToHuman()<CR>
" Makes `j` and `k` behave like you'd expect when `wrap` mode is turned on
nnoremap j gj
nnoremap k gk
""""""""""""""""""""""""""""""""""""""""
" JSX
""""""""""""""""""""""""""""""""""""""""
let g:jsx_ext_required = 0
""""""""""""""""""""""""""""""""""""""""
" Ale
""""""""""""""""""""""""""""""""""""""""
" tslint is busted with ALE at the moment, isn't respecting configs correctly
let g:ale_linters = {
\ 'rust': ['analyzer'],
\ 'typescript': ['tsserver', 'typecheck', 'eslint'],
\ 'go': ['gopls'],
\ 'scala': ['metals'],
\}
let g:ale_linters_ignore = {
\ 'javascript': ['jshint'],
\ 'javascriptreact': ['jshint'],
\}
let g:ale_fixers = {
\ 'rust': ['rustfmt'],
\ 'javascript': ['prettier'],
\ 'typescript': ['prettier'],
\ 'typescriptreact': ['prettier'],
\ 'html': ['prettier'],
\ 'go': ['gofmt'],
\ 'elm': ['elm-format'],
\ 'scala': ['scalafmt'],
\ 'php': ['php_cs_fixer'],
\}
let g:ale_completion_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_completion_delay = 300
let g:ale_rust_rustfmt_options = "--edition 2018"
nnoremap <Leader>d :ALEGoToDefinition<cr>
nnoremap <Leader>dx :ALEGoToDefinition -split<cr>
nnoremap <Leader>dv :ALEGoToDefinition -vsplit<cr>
nnoremap <Leader>h :ALEHover<cr>
""""""""""""""""""""""""""""""""""""""""
" NERDCommenter
""""""""""""""""""""""""""""""""""""""""
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
""""""""""""""""""""""""""""""""""""""""
" Goyo
""""""""""""""""""""""""""""""""""""""""
function! s:goyo_enter()
silent !tmux set status off
set nonumber
set norelativenumber
augroup numbertoggle
autocmd!
augroup END
endfunction
function! s:goyo_leave()
silent !tmux set status on
set number
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
endfunction
autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
""""""""""""""""""""""""""""""""""""""""
" Status Bar
""""""""""""""""""""""""""""""""""""""""
if has('statusline')
set laststatus=2
" Broken down into easily includeable segments
set statusline=%<%f\ " Filename
set statusline+=%w%h%m%r " Options
set statusline+=%{fugitive#statusline()} " Git Hotness
set statusline+=\ [%{&ff}/%Y] " Filetype
set statusline+=\ [%{getcwd()}] " Current dir
set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info
endif
""""""""""""""""""""""""""""""""""""""""
" Elixir
""""""""""""""""""""""""""""""""""""""""
autocmd BufWritePost *.exs silent :!mix format %
autocmd BufWritePost *.ex silent :!mix format %
""""""""""""""""""""""""""""""""""""""""
" Airline
""""""""""""""""""""""""""""""""""""""""
let g:airline_powerline_fonts = 1
let g:airline_theme = 'nord'
let g:airline_section_b = ''
let g:airline_section_y = ''
let g:airline_section_z = ''
let g:airline_skip_empty_sections = 1
""""""""""""""""""""""""""""""""""""""""
" EasyMotion
""""""""""""""""""""""""""""""""""""""""
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" Bi-directional find motion
nmap s <Plug>(easymotion-s)
" Turn on case sensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
nmap <Leader>j <Plug>(easymotion-j)
nmap <Leader>k <Plug>(easymotion-k)
""""""""""""""""""""""""""""""""""""""""
" NerdTree
""""""""""""""""""""""""""""""""""""""""
noremap <C-e> :NERDTreeToggle<CR>
noremap <Leader>e :NERDTreeFind<CR>
" Remove this mapping cause I don't like it. Normally running an `unmap` on an
" already unmapped key throws an error, the `silent!` suppresses that.
silent! nunmap <Leader>nt
let NERDTreeShowBookmarks=1
let NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr']
let NERDTreeChDirMode=0
let NERDTreeQuitOnOpen=1
let NERDTreeMouseMode=2
let NERDTreeShowHidden=1
let NERDTreeKeepTreeInNewTab=1
let NERDTreeWinSize=60
""""""""""""""""""""""""""""""""""""""""
" Tabularize
""""""""""""""""""""""""""""""""""""""""
nnoremap <Leader>a& :Tabularize /&<CR>
vnoremap <Leader>a& :Tabularize /&<CR>
nnoremap <Leader>a= :Tabularize /=<CR>
vnoremap <Leader>a= :Tabularize /=<CR>
nnoremap <Leader>a: :Tabularize /:<CR>
vnoremap <Leader>a: :Tabularize /:<CR>
nnoremap <Leader>a, :Tabularize /,<CR>
vnoremap <Leader>a, :Tabularize /,<CR>
nnoremap <Leader>a,, :Tabularize /,\zs<CR>
vnoremap <Leader>a,, :Tabularize /,\zs<CR>
nnoremap <Leader>a" :Tabularize /\"<CR>
vnoremap <Leader>a" :Tabularize /\"<CR>
nnoremap <Leader>a<Bar> :Tabularize /<Bar><CR>
vnoremap <Leader>a<Bar> :Tabularize /<Bar><CR>
""""""""""""""""""""""""""""""""""""""""
" Fugitive
""""""""""""""""""""""""""""""""""""""""
nnoremap <silent> <leader>gs :Git status<CR>
nnoremap <silent> <leader>gd :Git diff<CR>
nnoremap <silent> <leader>gc :Git commit<CR>
nnoremap <silent> <leader>gb :Git blame<CR>
nnoremap <silent> <leader>gl :Git log<CR>
nnoremap <silent> <leader>gp :Git it push<CR>
nnoremap <silent> <leader>gr :Gread<CR>
nnoremap <silent> <leader>gw :Git write<CR>
nnoremap <silent> <leader>ge :Git edit<CR>
" Mnemonic _i_nteractive
nnoremap <silent> <leader>gi :Git add -p %<CR>
nnoremap <silent> <leader>gg :SignifyToggle<CR>
""""""""""""""""""""""""""""""""""""""""
" Fzf.vim
""""""""""""""""""""""""""""""""""""""""
nnoremap <C-p> :GFiles<CR>
nnoremap <leader>p :Buffers<CR>
nnoremap <leader>; :History:<CR>
nnoremap <leader>/ :History/<CR>
""""""""""""""""""""""""""""""""""""""""
" Expand Region
""""""""""""""""""""""""""""""""""""""""
vnoremap v <Plug>(expand_region_expand)
vnoremap <C-v> <Plug>(expand_region_shrink)
""""""""""""""""""""""""""""""""""""""""
" GitGutter
""""""""""""""""""""""""""""""""""""""""
nmap [h <Plug>(GitGutterPrevHunk)
nmap ]h <Plug>(GitGutterNextHunk)
nmap <Leader>r <Plug>(GitGutterUndoHunk)
autocmd BufWritePost * GitGutter
""""""""""""""""""""""""""""""""""""""""
" VimWiki
""""""""""""""""""""""""""""""""""""""""
let wiki = {}
let wiki.path = '~/Dropbox/wiki'
let wiki.nested_syntaxes = {'javascript': 'javascript', 'yaml': 'yaml'}
let wiki.syntax = 'markdown'
let wiki.ext = 'md'
let g:vimwiki_list = [wiki]
" Disable table mapping so that UltiSnips can use <tab>
let g:vimwiki_table_mappings = 0
" Hide code blocks for cleanliness
let g:vimwiki_conceal_pre = 1
""""""""""""""""""""""""""""""""""""""""
" UtiliSnip
""""""""""""""""""""""""""""""""""""""""
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-j>"
let g:UltiSnipsJumpBackwardTrigger="<c-k>"
""""""""""""""""""""""""""""""""""""""""
" Functions
""""""""""""""""""""""""""""""""""""""""
function! ReplaceAndExecLine()
let template = getline('.')
" This is hacky, but this line expects the first line if the file to have a
" `let vars = {}` statement
exec getline(1)
for key in keys(vars)
let template = substitute(template, key, get(vars, key), "g")
endfor
exec 'r! ' . template
endfunction
function! StripTrailingWhitespace()
" Save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" do the business:
%s/\(\|\s\)\+$//e
" clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" fill rest of line with characters http://stackoverflow.com/a/3400528/895558
" Call with :call FillLine('-')
" Can also do `100A-<Esc>d80|` leveraging the column motion pipe character
function! FillLine( str )
" set tw to the desired total length
let tw = &textwidth
if tw==0 | let tw = 80 | endif
" strip trailing spaces first
.s/[[:space:]]*$//
" calculate total number of 'str's to insert
let reps = (tw - col("$")) / len(a:str)
" insert them, if there's room, removing trailing spaces (though forcing
" there to be one)
if reps > 0
.s/$/\=(' '.repeat(a:str, reps))/
endif
endfunction
" This function reads the number under the cursor and transforms it into
" something human readable
function! BytesToHuman()
" Get text under cursor
let l:numBytes = str2nr(expand("<cword>"), 10)
let l:k = 1024
let l:sizes = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
let l:i = float2nr(floor(log10(l:numBytes) / log10(l:k)))
let l:humanReadable = printf("%.2f%s", l:numBytes / pow(l:k, l:i), l:sizes[l:i])
call setline(".", substitute(getline("."), l:numBytes, l:humanReadable, ""))
endfunction
""""""""""""""""""""""""""""""""""""""""
" Overrides
""""""""""""""""""""""""""""""""""""""""
" Import the 'after' override file if it exists
if filereadable(expand('~/.vimrc-after'))
source ~/.vimrc-after
endif