-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
440 lines (376 loc) · 12.4 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
" BB .vimrc
" Plug-in installation calls for vim-plug
call plug#begin('~/.vim/plugged')
" TPope Commentary
Plug 'https://github.com/tpope/vim-commentary.git'
" TPope Endwise (add end intelligently with Ruby)
Plug 'https://github.com/tpope/vim-endwise.git'
" TPope Vinegar (netrw improvements)
Plug 'https://github.com/tpope/vim-vinegar.git'
" TPope Dispatch
Plug 'https://github.com/tpope/vim-dispatch.git'
" AsyncRun (used for Frotz / Interactive Fiction)
Plug 'https://github.com/skywind3000/asyncrun.vim.git'
" ALE (language linting)
Plug 'https://github.com/dense-analysis/ale.git'
" Vader (vim testing)
Plug 'https://github.com/junegunn/vader.vim.git'
" Goyo for prose writing
Plug 'https://github.com/junegunn/goyo.vim.git'
" Vim-Pencil for prose writing
Plug 'https://github.com/preservim/vim-pencil.git'
" VOoM Outliner
Plug 'https://github.com/vim-voom/VOoM.git'
" Ripgrep
Plug 'https://github.com/jremmen/vim-ripgrep.git'
" Compilers (need the bash for Dispatch)
Plug 'https://github.com/Konfekt/vim-compilers.git'
" Rainbow Parentheses
Plug 'https://github.com/junegunn/rainbow_parentheses.vim.git'
" Vlime
Plug 'https://github.com/vlime/vlime.git'
" Parinfer
Plug 'https://github.com/bhurlow/vim-parinfer.git'
" Match-up
Plug 'https://github.com/andymass/vim-matchup.git'
" vim-rec
Plug 'https://github.com/zaid/vim-rec.git'
" HTML5 indentation fixes
Plug 'https://github.com/othree/html5.vim'
" Odin
Plug 'https://github.com/Tetralux/odin.vim.git'
" Iceberg
Plug 'https://github.com/cocopon/iceberg.vim.git'
" Apprentice
Plug 'https://github.com/romainl/Apprentice.git'
" Nightfly
Plug 'https://github.com/bluz71/vim-nightfly-colors.git'
call plug#end()
set nocompatible
set shell=bash
" NOTE: Order matters here.
set termguicolors
set background=dark
colorscheme nightfly
syntax on
filetype plugin on
" Bracketed paste
let &t_BE = "\e[?2004h"
let &t_BD = "\e[?2004l"
let &t_PS = "\e[200~"
let &t_PE = "\e[201~"
" Vlime config
let g:vlime_leader=","
" Recutils
let g:recutils_no_folding=1
" Open Netrw splits in the right hand side
let g:netrw_altv=1
"Ctrl+Shift+up move line above"
nmap <C-S-Up> :m -2<CR>
"Ctrl+Shift+down move line below
nmap <C-S-Down> :m +1<CR>
" Highlight the current line
set cursorline
" Display title of file/folder
set title
" VOOm width
let g:voom_tree_width=38
" Display line numbers
set number
set relativenumber
" Easily copy and paste in an out of Vim
set clipboard=unnamed
" Change split size with the mouse
set mouse=n
" Only look at tags and current file for autocomplete
set complete=.,t
" Ale linter settings
let g:ale_linters = {
\ 'ruby': ['rubocop', 'reek'],
\ 'eruby': ['erblint'],
\ 'javascript': ['eslint'],
\ 'tcl': ['nagelfar'],
\ 'odin': ['ols'],
\}
let g:ale_sign_error = '!!'
let g:ale_sign_warning = '??'
let g:ale_sign_info = 'oo'
let g:ale_linters_explicit = 1
let g:ale_list_window_size = 5
let g:ale_virtualtext_cursor = 'disabled'
" let g:ale_odin_ols_config = {
" \ 'initializationOptions': {
" \ 'collections': [
" \ {
" \ 'name': 'core',
" \ 'path': '/Users/bdb/build/Odin/core'
" \ }
" \ ],
" \ 'disable_parser_errors': 'true'
" \ }
" \}
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
" Use the line number column for ALE signs
set signcolumn=number
" Background color fix for Kitty
let &t_ut=''
" Use an undo file
set undofile
" Storing the undo, swap files in a nice place.
setglobal undodir=$HOME/.vim/tmp//
setglobal backupdir=$HOME/.vim/tmp//
setglobal directory=$HOME/.vim/tmp//
if !isdirectory(&undodir)
call mkdir(&undodir)
end
" Search down into subfolders
" Provides tab-completion for all file-related tasks
set path+=**
" Display all matching files when we tab complete
set wildmenu
" Ignore node module directory. Lots of noise.
" Helps massively with Command+T performance.
set wildignore+=*/node_modules
set wildignore+=*/tmp
set wildignore+=*/storage
set wildignore+=*/app/assets/fonts
" Default tab and indent settings
set autoindent " Autoindent when making new line
set tabstop=2 " Set tabs to 2 spaces when reading file
set softtabstop=2 " Set tabs to 2 space when editing
set shiftwidth=2
set expandtab " Make tabs spaces, not <TAB>
" Only redraw when required
" set lazyredraw
" Show the status line at the bottom
set ls=2
set showmatch
" Search settings
set incsearch
set hlsearch
set ignorecase
set smartcase
" Adding spacebar as an additional leader
let mapleader="\<Space>"
" Clear out highlighted search terms
nnoremap <leader>, :nohlsearch<CR>
" Return to previous buffer with leader+backspace
nnoremap <leader><BS> <C-^>
" Insert a hash rocket with <c-l>
imap <c-l> <space>=><space>
" Unfuck my screen
nnoremap U :syntax on<cr>:syntax sync fromstart<cr>:redraw!<cr>
" Allow backspacing over everything in insert mode
set backspace=indent,eol,start
" Show one line above/below cursor at edge of buffer
" Pulled from TPope's Sensible repo
if !&scrolloff
set scrolloff=3
endif
if !&sidescrolloff
set sidescrolloff=5
endif
set display+=lastline
" Make set :list display better (showing whitespace chars)
if &listchars ==# 'eol:$'
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
endif
" Reload Safari with <leader>r if there is a bin/reload
" file in the current working directory
if filereadable('bin/reload')
nnoremap <leader>r :w\|Dispatch! bin/reload<cr>
endif
" fzy for fuzzy search
function! FzyCommand(choice_command, fzy_args, vim_command)
try
let selection = system(a:choice_command . " | fzy " . a:fzy_args)
catch /Vim:Interrupt/
" Swallow the ^C so that the redraw below happens; otherwise there will be
" leftovers from fzy on the screen
redraw!
return
endtry
redraw!
exec a:vim_command . " " . selection
endfunction
nnoremap <leader>t :call FzyCommand("fd -t f -H", "", ":e")<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ruby block indentation
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" From Gary Bernhardt's .vimrc
" Do this:
" first
" .second do |x|
" something
" end
" Not this:
" first
" .second do |x|
" something
" end
:let g:ruby_indent_block_style = 'do'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SWITCH BETWEEN TEST AND PRODUCTION CODE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! OpenTestAlternate()
let new_file = AlternateForCurrentFile()
exec ':e ' . new_file
endfunction
function! AlternateForCurrentFile()
let current_file = expand("%")
let new_file = current_file
let in_test = match(current_file, '^test/') != -1
let going_to_test = !in_test
let in_app = match(current_file, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<workers\>') != -1 || match(current_file, '\<views\>') != -1 || match(current_file, '\<helpers\>') != -1 || match(current_file, '\<services\>') != -1 || match(current_file, '\<jobs\>') != -1
if going_to_test
if in_app
let new_file = substitute(new_file, '^app/', '', '')
end
let new_file = substitute(new_file, '\.e\?rb$', '_test.rb', '')
let new_file = 'test/' . new_file
else
let new_file = substitute(new_file, '_test\.rb$', '.rb', '')
let new_file = substitute(new_file, '^test/', '', '')
if in_app
let new_file = 'app/' . new_file
end
endif
return new_file
endfunction
nnoremap <leader>. :call OpenTestAlternate()<cr>
" Ruby debugging
nnoremap <leader>wtf oputs "#" * 90<c-m>puts caller<c-m>puts "#" * 90<esc>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SMART FILE DEFAULTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
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
" For Ruby et. al., autoindent with two spaces, always expand tabs
autocmd! FileType ruby,haml,eruby,yaml,html,sass,cucumber,sql set ai sw=2 sts=2 et
" Python settings
autocmd! FileType python set sw=4 sts=4 et
" Odin
autocmd! FileType odin set autoindent copyindent preserveindent tabstop=4 shiftwidth=4 softtabstop=0 noexpandtab
" Sass
autocmd! BufRead,BufNewFile *.sass setfiletype sass
" Markdown settings
autocmd! BufRead *.mkd set ai formatoptions=tcroqn2 comments=n:>
autocmd! BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:>
autocmd! FileType markdown set sw=4 sts=4 et
autocmd! BufRead *.vcl set sw=4 sts=4 et
" JS
autocmd! FileType javascript set sw=2 sts=2 expandtab
" Two-space indents in json
autocmd! FileType json set sw=2 sts=2 expandtab
" Lisp settings
autocmd FileType lisp,clojure,scheme RainbowParentheses
autocmd filetype lisp,clojure,scheme setlocal equalprg=lispindent.lisp
" Hitting K in a Ruby file opens rdoc, which completely breaks the terminal
" to the point of having to kill vim and do `reset`. Unmap it entirely.
nnoremap K <Nop>
" Makefile
autocmd FileType make set noexpandtab sw=2 sts=2
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Prose Mode
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function EnableProseMode()
setlocal nocursorline nospell linebreak
Goyo 110
SoftPencil
setlocal cole=2
set conceallevel=0
Voom markdown
echo "Prose Mode"
endfu
" Enter ProseMode
command Prose call EnableProseMode()
nnoremap ,p :Prose<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Note taking mode
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function EnableVOoM()
Voom markdown
echo "Note Mode"
endfu
command VOoM call EnableVOoM()
nnoremap ,n :VOoM<CR>
" Open a StarDict definition in a ScratchBuffer
function ScratchBufferize()
setlocal buftype=nofile
setlocal bufhidden=hide
setlocal noswapfile
endfu
nnoremap ,d :new \| read ! sdcv <C-R><C-W> <CR>:call ScratchBufferize() <CR>:normal gg<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUNNING TESTS
"
" Test running here is contextual in two different ways:
"
" 1. It will guess at how to run the tests. E.g., if there's a Gemfile
" present, it will `bundle exec rspec` so the gems are respected.
"
" 2. It remembers which tests have been run. E.g., if I'm editing user_spec.rb
" and hit enter, it will run rspec on user_spec.rb. If I then navigate to a
" non-test file, like routes.rb, and hit return again, it will re-run
" user_spec.rb. It will continue using user_spec.rb as my 'default' test
" until I hit enter in some other test file, at which point that test file
" is run immediately and becomes the default. This is complex to describe
" fully, but simple to use in practice: always hit enter to run tests. It
" will run either the test file you're in or the last test file you hit
" enter in.
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! MapCR()
nnoremap <cr> :call RunTestFile()<cr>
endfunction
call MapCR()
function! RunTestFile(...)
if a:0
let command_suffix = a:1
else
let command_suffix = ""
endif
" Are we in a test file?
let in_test_file = match(expand("%"), '\(_test.rb\)$') != -1
" Run the tests for the previously-marked file (or the current file if
" it's a test).
if in_test_file
call SetTestFile(command_suffix)
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file)
endfunction
function! SetTestFile(command_suffix)
" Set the spec file that tests will be run for.
let t:grb_test_file=@% . a:command_suffix
endfunction
function! RunTests(filename)
" Write the file and run tests for the given filename
if expand("%") != ""
:w
end
" The file is executable; assume we should run
if executable(a:filename)
exec ":!./" . a:filename
" Project-specific test script
elseif filereadable("bin/test")
exec ":!bin/test " . a:filename
" Fall back to a blocking test run with Bundler
elseif filereadable("Gemfile") && strlen(glob("test/**/*.rb"))
exec ":!bin/rails test " . a:filename
end
endfunction
" Insert a default odin main proc with DEBUG info added.
function! MapOdinMainProc()
nnoremap <leader>odin :r~/.vim/snippets/default.odin<CR>
endfunction
call MapOdinMainProc()