-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
495 lines (399 loc) · 13.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
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
" *********************************************
" * Vim Plugins *
" *********************************************
call plug#begin()
" Navigation
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug '/opt/homebrew/opt/fzf'
Plug 'preservim/nerdtree'
Plug 'vim-scripts/IndexedSearch'
Plug 'vim-scripts/matchit.zip'
Plug 'tpope/vim-unimpaired'
Plug 'jeetsukumaran/vim-buffergator'
Plug 'ludovicchabant/vim-gutentags'
" Syntax
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
Plug 'slim-template/vim-slim'
Plug 'mtscout6/vim-cjsx'
Plug 'mxw/vim-jsx'
Plug 'hashivim/vim-terraform'
Plug 'jparise/vim-graphql'
" Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'editorconfig/editorconfig-vim'
Plug 'cespare/vim-toml'
Plug 'uarun/vim-protobuf'
" Typescript
Plug 'HerringtonDarkholme/yats.vim'
" Gist
Plug 'mattn/webapi-vim'
Plug 'mattn/gist-vim'
" Formatting
Plug 'scrooloose/nerdcommenter'
Plug 'godlygeek/tabular'
Plug 'editorconfig/editorconfig-vim'
Plug 'prettier/vim-prettier', { 'do': 'yarn install --frozen-lockfile --production' }
" Autocomplete
Plug 'tpope/vim-surround'
Plug 'tpope/vim-endwise'
Plug 'msanders/snipmate.vim'
Plug 'mattn/emmet-vim'
Plug 'Raimondi/delimitMate'
Plug 'ervandew/supertab'
" Bar
Plug 'itchyny/lightline.vim'
" Markdown
Plug 'suan/vim-instant-markdown'
Plug 'rizzatti/funcoo.vim'
Plug 'rizzatti/dash.vim'
Plug 'tpope/vim-dispatch'
" Git
Plug 'sjl/gundo.vim'
" Rails
Plug 'tpope/vim-rails'
Plug 'tpope/vim-rake'
Plug 'tpope/vim-haml'
" Cucumber
Plug 'tpope/vim-cucumber'
" Elixir
Plug 'elixir-lang/vim-elixir'
" Python
Plug 'nvie/vim-flake8'
Plug 'vim-scripts/indentpython'
" Git
Plug 'tpope/vim-fugitive'
" JS tests
Plug 'janko-m/vim-test'
" Async linting
Plug 'w0rp/ale'
" Color
Plug 'w0ng/vim-hybrid'
" Plug 'joshdick/onedark.vim'
" Debugging
Plug 'puremourning/vimspector'
call plug#end()
" *********************************************
" * Settings *
" *********************************************
syntax enable
filetype plugin indent on " load file type plugins + indentation
set showcmd " Display incomplete commands.
set showmode " Display the mode you're in.
set showmatch " Show matching brackets/parenthesis
" ctags
set tags=tags
set noswapfile
set nobackup
set nowb
set colorcolumn=80
set cursorline
set list listchars=tab:\ \ ,trail:·
set nowrap " don't wrap lines
set tabstop=2 shiftwidth=2 " a tab is two spaces
set expandtab " use spaces, not tabs
set backspace=indent,eol,start " backspace through everything in insert mode
set autoindent " match indentation of previous line
set pastetoggle=<F2>
set incsearch " Find as you type search
set hlsearch " Highlight search terms
set ignorecase " Case-insensitive searching.
set smartcase " But case-sensitive if expression contains a capital letter.
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "dont fold by default
set hidden " Handle multiple buffers better.
set title " Set the terminal's title
set number " Show line numbers.
set ruler " Show cursor position.
set wildmode=list:longest " Complete files like a shell.
set wildmenu " Enhanced command line completion.
set novisualbell
set noerrorbells
set history=1000 " Store lots of :cmdline history
set scrolloff=3
set sidescrolloff=7
set mouse-=a
set mousehide
if !has('nvim')
set ttymouse=xterm2
endif
set sidescroll=1
set nobackup " Don't make a backup before overwriting a file.
set nowritebackup " And again.
set directory=/tmp " Keep swap files in one location
set timeoutlen=500
set laststatus=2 " Show the status line all the time
set statusline=%f
" color scheme
set background=dark
colorscheme hybrid
let g:disable_float_bg = 1
set shell=/bin/zsh
" hide the tilde's at the end of the buffer
highlight EndOfBuffer ctermfg=black ctermbg=black
" *********************************************
" * Functions *
" *********************************************
" Find Cucumber's unused steps
command! CucumberFindUnusedSteps :call CucumberFindUnusedSteps()
function! CucumberFindUnusedSteps()
let olderrorformat = &l:errorformat
try
set errorformat=%m#\ %f:%l
cexpr system('bundle exec cucumber --no-profile --no-color --format usage --dry-run features \| grep "NOT MATCHED BY ANY STEPS" -B1 \| egrep -v "(--\|NOT MATCHED BY ANY STEPS)"')
cwindow
finally
let &l:errorformat = olderrorformat
endtry
endfunction
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
" *********************************************
" * Key Bindings *
" *********************************************
let mapleader = ","
" ============================
" Rails
" ============================
" Better key maps for switching between controller and view
nnoremap ,vv :Rview<cr>
nnoremap ,cc :Rcontroller<cr>
" Clear last search highlighting
nnoremap <Space> :noh<cr>
" Create window splits easier. The default
" way is Ctrl-w,v and Ctrl-w,s. I remap
" this to vv and ss
nnoremap <silent> vv <C-w>v
nnoremap <silent> ss <C-w>s
" paste
nnoremap <silent> pp :read !pbpaste<CR>
"Clear current search highlight by double tapping //
nmap <silent> // :nohlsearch<CR>
" Flip buffers
nnoremap <Leader>l :ls<CR>
nnoremap <Leader>b :bp<CR>
" nnoremap <Leader>f :bn<CR>
nnoremap <Leader>g :e#<CR>
nnoremap <Leader>1 :1b<CR>
nnoremap <Leader>2 :2b<CR>
nnoremap <Leader>3 :3b<CR>
nnoremap <Leader>4 :4b<CR>
nnoremap <Leader>5 :5b<CR>
nnoremap <Leader>6 :6b<CR>
nnoremap <Leader>7 :7b<CR>
nnoremap <Leader>8 :8b<CR>
nnoremap <Leader>9 :9b<CR>
nnoremap <Leader>0 :10b<CR>
" Easier navigation between split windows
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
" Debugging
let g:vimspector_base_dir='/Users/nicholash/.vim/plugged/vimspector'
nnoremap <Leader>dd :call vimspector#Launch()<CR>
nnoremap <Leader>de :call vimspector#Reset()<CR>
nnoremap <Leader>dc :call vimspector#Continue()<CR>
nnoremap <Leader>dt :call vimspector#ToggleBreakpoint()<CR>
nnoremap <Leader>dT :call vimspector#ClearBreakpoints()<CR>
nmap <Leader>dk <Plug>VimspectorRestart
nmap <Leader>dh <Plug>VimspectorStepOut
nmap <Leader>dl <Plug>VimspectorStepInto
nmap <Leader>dj <Plug>VimspectorStepOver
" Insert blank lines without going into insert mode
nmap go o<esc>
nmap gO O<esc>
" Shortcut for =>
imap <C-l> <Space>=><Space>
" indent/unindent visual mode selection with tab/shift+tab
vmap <tab> >gv
vmap <s-tab> <gv
" F7 reformats the whole file and leaves you where you were (unlike gg)
map <silent> <F7> mzgg=G'z :delmarks z<CR>:echo "Reformatted."<CR>
" instant markdown
let g:instant_markdown_autostart = 0
" typescript deoplete
let g:deoplete#enable_at_startup = 1
" for deoplete
let g:python_host_prog = "/usr/local/bin/python2"
let g:python3_host_prog = "/usr/local/bin/python3"
" open files in directory of current file
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>v :view %%
" execute current file
map <leader>e :!%:p<cr>
" rename current file
map <leader>n :call RenameFile()<cr>
" Auto open NERDTree
au VimEnter * NERDTree
" File tree browser - backslash
map \ :NERDTreeToggle<CR>
" File tree browser showing current file - pipe
map \| :NERDTreeFind<CR>
" Ignore files in nerdtree
let NERDTreeShowHidden=1
let NERDTreeIgnore = ['\.pyc$', '^node_modules', '\.log$', 'public\/system',
\ 'javascripts\/bundle', '^spec\/dummy', '^bower_components', '\.git',
\ '\.DS_Store', '\.vscode', '__pycache__', '^tags', '^tags.lock$',
\ '^tags.temp$', '^coverage', '^build\/', '__init__.py']
" Go to previous (last accessed) window to focus on file
autocmd VimEnter * wincmd p
" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | call feedkeys(":quit\<CR>:\<BS>") | endif
silent! map <unique> <Leader>w :!bundle exec cucumber --profile=wip<CR>
" Remove trailing whitspace on save
autocmd FileType c,cpp,python,ruby,java,javascript autocmd BufWritePre <buffer> :%s/\s\+$//e
" *********************************************
" * Plugin Customization *
" *********************************************
" Override filetype
au BufRead,BufNewFile *.html setf htmldjango
au BufNewFile,BufRead *.ejs setf html.js
au BufNewFile,BufRead *.slim setf slim
au BufNewFile,BufRead Gemfile setf ruby
au BufNewFile,BufRead *.rake setf ruby
au BufNewFile,BufRead *.cap setf ruby
au BufNewFile,BufRead *.config setf zsh
au BufNewFile,BufRead *.json setf javascript
au BufNewFile,BufRead *.proto setf proto
au BufNewFile,BufRead *.gradle setf groovy
au BufNewFile,BufRead Jenkinsfile setf groovy
au BufNewFile,BufRead *.py setf python
au BufNewFile,BufRead *.rb setf ruby
au BufNewFile,BufRead *.template setf conf
au BufNewFile,BufRead Dockerfile* setf Dockerfile
" Groovy
au FileType groovy
\ set tabstop=4 |
\ set shiftwidth=4 |
\ set softtabstop=4
" Python
au Filetype python
\ set tabstop=4 |
\ set shiftwidth=4 |
\ set softtabstop=4 |
\ set textwidth=79 |
" Highlighting
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_structs = 1
let g:go_highlight_types = 1
" Groovy
" flake8
let g:flake8_ignore="E403,E128,F403"
" syntax alias
autocmd BufNewFile,BufRead *.conf set syntax=config
" go
" let g:go_auto_sameids = 1
" *********************************************
" * Local Vimrc Customization *
" *********************************************
if filereadable(expand('~/.vimrc.local'))
so ~/.vimrc.local
endif
function! RSpecFile()
execute "Dispatch docker-compose exec app rspec " . expand("%p")
endfunction
map <leader>R :call RSpecFile() <CR>
command! RSpecFile call RSpecFile()
function! RSpecCurrent()
execute "Dispatch docker-compose exec app rspec " . expand("%p") . ":" . line(".")
endfunction
map <leader>r :call RSpecCurrent() <CR>
command! RSpecCurrent call RSpecCurrent()
let g:test#strategy = 'dispatch'
let g:test#runner_commands = ['Mocha']
let test#javascript#mocha#options = '--compilers js:babel-core/register --recursive'
" redraw everything
map <leader>d :redraw! <CR>
" Lightline
let g:lightline = {
\ 'colorscheme': 'rosepine',
\ 'active': {
\ 'left': [['mode', 'paste'], ['filename', 'modified']],
\ 'right': [['lineinfo'], ['percent'], ['readonly', 'linter_warnings', 'linter_errors', 'linter_ok']]
\ },
\ 'component_expand': {
\ 'linter_warnings': 'LightlineLinterWarnings',
\ 'linter_errors': 'LightlineLinterErrors',
\ 'linter_ok': 'LightlineLinterOK'
\ },
\ 'component_type': {
\ 'readonly': 'error',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error'
\ },
\ 'component_function': {
\ 'filename': 'LightLineFilename'
\ },
\ }
function! LightLineFilename()
return expand('%')
endfunction
function! LightlineLinterWarnings() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ◆', all_non_errors)
endfunction
function! LightlineLinterErrors() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ✗', all_errors)
endfunction
function! LightlineLinterOK() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '✓ ' : ''
endfunction
autocmd User ALELint call s:MaybeUpdateLightline()
" Update and show lightline but only if it's visible (e.g., not in Goyo)
function! s:MaybeUpdateLightline()
if exists('#lightline')
call lightline#update()
end
endfunction
" ale
let g:ale_set_highlights = 0
" vim-jsx
let g:jsx_ext_required = 0
" fzf
nnoremap <Leader>ff :GitFiles<CR>
nnoremap <Leader>fb :Buffers<CR>
nnoremap <C-p> :GitFiles<CR>
nnoremap <C-t> :RG<CR>
nnoremap <silent><leader>f :FZF -q <C-R>=expand("<cword>")<CR><CR>
" ripgrep
let g:rg_highlight = 1
set grepprg=rg\ --vimgrep\ --smart-case\ --hidden\ --follow
let g:rg_derive_root='true'
nnoremap <C-T> :Files<cr>
nnoremap <Leader>b :Buffers<cr>
nnoremap <Leader>s :BLines<cr>
" --column: Show column number
" --line-number: Show line number
" --no-heading: Do not show file headings in results
" --fixed-strings: Search term as a literal string
" --ignore-case: Case insensitive search
" --hidden: Search hidden files and folders
" --follow: Follow symlinks
" --glob: Additional conditions for search (in this case ignore everything in the .git/ folder)
" --color: Search color options
" command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>), 1, <bang>0)
" datetime
:nnoremap <F5> "=strftime("%FT%T%z")<CR>P
:inoremap <F5> <C-R>=strftime("%FT%T%z")<CR>