-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.vimrc
415 lines (346 loc) · 14.3 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
call plug#begin()
Plug 'elixir-lang/vim-elixir', { 'for': 'elixir' }
Plug 'flazz/vim-colorschemes'
Plug 'jlanzarotta/bufexplorer'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/vim-easy-align'
Plug 'kien/rainbow_parentheses.vim'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-surround'
Plug 'vim-airline/vim-airline'
Plug 'vim-ruby/vim-ruby'
Plug 'w0rp/ale'
Plug 'github/copilot.vim'
call plug#end()
"Plug 'vim-syntastic/syntastic'
exe "set path=".expand("$PATH")
" :echo g:colors_name to find out current color scheme
" colorscheme desert
" colorscheme desert256
colorscheme desert256v2
" colorscheme darkocean
" colorscheme evening_2
" I like these colors better but the visual highlighting mode is terrible
" colorscheme wombat
" colorscheme zenburn
" colorscheme solarized
" change the default EasyMotion shading to something more readable with many
" color schemes
hi link EasyMotionTarget ErrorMsg
hi link EasyMotionShade Comment
" This fixes the visual highlighting being too light
" autocmd VimEnter,Colorscheme * :hi Visual term=reverse cterm=reverse guibg=LightGrey
" When using non-terminal vim this proved necessary and can't hurt to have anyway
set background=dark
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd guibg=red ctermbg=3
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven guibg=green ctermbg=4
set nocompatible " We're running Vim, not Vi!
syntax on " Enable syntax highlighting
filetype plugin indent on " Enable filetype-specific indenting and plugins
let mapleader = ","
runtime! macros/matchit.vim
" show line numbers
set number
" history for vim
set viminfo='100,\"50,<500,:100 " 100 files, 50 registers, 500 lines in registers, 100 command history
"set history=100000
" remember buffers between sessions - strange, didnt need this until using mac
:exec 'set viminfo=%,' . &viminfo
" Tab spacing
set shiftwidth=2 "number of space characters inserted for indentation
set tabstop=2 "number of space characters for tab key
set expandtab "use spaces instead of tab characters
set sw=2 " Shift width
set smarttab
set ai "Auto indent
"set list listchars=tab:>-, trail:., extends:>, precedes:<, eol:$
" show trailing whitespace without being annoying
set list listchars=tab:>-,trail:.,extends:>,precedes:<
" Remove trailing whitespace whenever I save
" But it makes it hard to do separate whitespace commits
" autocmd BufWritePre * :%s/\s\+$//e
" turn off paste on save because I forget to and it messes up my formatting
autocmd BufWritePre * :set nopaste
" file name completion
set wildmenu
set wildmode=list,full
" Status Line
" set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
"set statusline=[%n]\ %.300F\ %(\ %M%R%H)%)\%=\@(%l\,%c%V)\ %P
"set statusline=%F%m%r%h%w\ (%{&ff}){%Y}[%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
"set statusline=%<%F%h%m%r%h%w%y\ %{&ff}\ %{strftime(\"%d/%m/%Y-%H:%M\")}%=\ col:%c%V\ ascii:%b\ pos:%o\ lin:%l\,%L\ %P
"set statusline=%<%F%h%m%r%h%w%y\ %{&ff}\ %{strftime(\"%c\",getftime(expand(\"%:p\")))}%=\ lin:%l\,%L\ col:%c%V\ pos:%o\ ascii:%b\ %P
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}
set laststatus=2 "Always show status line
set encoding=utf-8 " Necessary to show Unicode glyphs
" highlight StatusLine ctermfg=darkblue ctermbg=grey
" Searching
set ignorecase
set smartcase " Smart case in search patterns when 'ignorecase' is on
set incsearch " Incremental search
set hlsearch " highlight matches
" doesn't work with nvim, do I still need it?
"set hl=l:Visual " make highlights easier to see
" Still trying to figure out if the mouse is usefull. Messes up copy paste from terminal
" set mouse=nv
" Buffers
" previous buffer
map <leader>bp <C-^>
set hidden " allow unsaved hidden buffers
" working directory is whatever file you're working in, not root
" but this messes up Gblame, screw Gblame, I can change to root if I need it
" autocmd BufEnter * lcd %:p:h:gs/ /\\ /
" For modifying the .vimrc
nmap <leader>e :e $HOME/.vimrc<cr>
nmap <leader>s :write!<cr>:source $HOME/.vimrc<cr>
" For modifying the .bashrc
" nmap <leader>b :e $HOME/.bashrc<cr>
" nmap <leader>d :write!<cr>:!source $HOME/.bashrc<cr>
" pasting without alignment problems
"map! <leader>p <Esc>:set paste!<cr>i
"map <leader>p :set paste!<cr>i
set pastetoggle=<leader>p
" Perl Debugging
" map <leader>dd A<cr>use Data::Dump qw/ dump /;<cr>die dump
" map <leader>wd A<cr>use Data::Dump qw/ dump /;<cr>warn dump
" Folding and unfolding
" I almost never use these anymore now that I'm not in Perl
map <leader>f :set foldmethod=indent<cr>zM<cr>
map <leader>F :set foldmethod=manual<cr>zR<cr>
" Toggling the taglist
"map <leader>l :TlistToggle<cr>
" Reformat sql to look nice
map <leader>sql <Esc>:g/,/:%s/, /,\r/g<cr>:%s/select /select\r/<cr>:%s/from\\|where\\|group by\\|order by/\r&/g<cr>:%s/\(from\\|where\\|group by\\|order by\) /&\r/g<cr>:g/ inner join/:%s/ inner join/\rinner join/g<cr>:g/ and/:%s/ and/\rand/g<cr>:g!/select\\|from\\|where\\|group by\\|order by\\|\//><cr>
" Highlights code that goes beyond 100 chars
match Todo '\%101v'
" Run Ruby unit tests with gT (for all) or gt (only test under
" cursor) in command mode
augroup RubyTests
au!
autocmd BufRead,BufNewFile *_test.rb,test_*.rb
\ :nmap <leader>t V:<C-U>!$HOME/.vim/ruby_run_focused_unit_test
\ % <C-R>=line("'<")<CR>p <CR>|
\ :nmap <leader>T :<C-U>!ruby %<CR>
augroup END
" Twitter - this hasn't been too useful, I'll probably delete it soon
if filereadable(expand($HOME . "/.vim_private_mattrobinsonnet"))
map <leader>pw <Esc>:source ~/.vim_private_mattrobinsonnet<cr>:PosttoTwitter<cr>
endif
if filereadable(expand($HOME . "/.vim_private_mmrobins"))
map <leader>pp <Esc>:source ~/.vim_private_mmrobins<cr>:PosttoTwitter<cr>
endif
" Use ack instead of grep
set grepprg=ack\ -a\ --nobinary\ --sort-files\ --color
"puppet test switching - may want to encapsulate this for other projects if I find I need that
function! GoToTheImplementation()
if match( expand("%:p"), "spec" ) > -1
exec(":A")
endif
endfunc
function! GoToTheTest()
if match( expand("%:p"), "spec" ) <= 0
exec(":A")
endif
endfunc
map <leader>gt :call GoToTheTest()<CR>
map! <leader>gt <ESC>:call GoToTheTest()<CR>i
map <leader>gi :call GoToTheImplementation()<CR>
map! <leader>gi <ESC>:call GoToTheImplementation()<CR>i
" showing git diffs
map <leader>sd :w!<CR>:! git diff --color-words HEAD %<CR>
map! <leader>sd <ESC>:w!<CR>:! git diff --color-words HEAD %<CR>
function! RunSpec(args)
" if exists("b:rails_root") && filereadable(b:rails_root . "/script/spec")
" :call CdRoot()
" let spec = b:rails_root . "/script/spec"
" let cmd = ":!" . spec . ' ' . expand("%:p") . " -cfn --debugger --loadby mtime --backtrace " . a:args
" else
let spec = "bundle exec rspec"
let cmd = ":!" . spec . ' ' . expand("%:p") . a:args . " -bcfd "
" end
execute cmd
endfunction
" run one rspec example or describe block based on cursor position
map <leader>t <ESC>:w<cr>:call GoToTheTest()<CR>:call RunSpec(":" . <C-r>=line('.')<CR>)<CR>
" run full rspec file
map <leader>T <ESC>:w<cr>:call GoToTheTest()<CR>:call RunSpec("")<CR>
" remove trailing whitespace
map <leader>wt :%s/\s\+$//<cr>
map! <leader>wt <esc>:%s/\s\+$//<cr>i
" change to the root of the project director so long as the project is under
" the work directory
function! CdRoot()
if match( expand("%:p"), "work/" ) > -1
:cd %:p:s?\(work/.\{-}/\).*?\1?
endif
endfunction
map <leader>cr <esc>:call CdRoot()<CR>
map <leader>cf <esc>:cd %:p:h:gs/ /\\ /<CR>
" old habits
map <leader>ack <esc>:call CdRoot()<CR>:Rg
" depends on fzf
map <leader>rg <esc>:call CdRoot()<CR>:Rg
"map <leader>pr A<cr>require 'profiler'<cr>Profiler__::start_profile<cr>Profiler__::stop_profile<cr>Profiler__::print_profile($stderr)<ESC>
map <leader>pr A<cr>require 'ruby-prof'<cr>RubyProf.start<cr>rprofresult = RubyProf.stop<cr>printer = RubyProf::GraphPrinter.new(rprofresult)<cr>printer.print(STDOUT,0)<ESC>
" Insert debugger into code at cursor
map <leader>rd A<cr>require 'debugger'; debugger<ESC>
map <leader>rb A<cr>require 'byebug'; byebug<ESC>
map <leader>ep A<cr>require IEx; IEx.pry<ESC>
map <leader>rp A<cr>binding.pry<ESC>
map <leader>jd A<cr>debugger;<ESC>
map <leader>jc A<cr>console.log();<ESC>hi
" central store for swap files instead of having them sprinkled throughout my projects
"set backupdir=~/.vim/backup//
"set directory=~/.vim/swp//
" I just don't need swap, have git and save all the time
set nobackup
set noswapfile
" Syntastic syntax checking on save
"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 = 1
"let g:syntastic_check_on_wq = 0
"
"let g:syntastic_enable_signs=1
"let g:syntastic_disabled_filetypes = ['prolog', 'html']
"let g:syntastic_javascript_checkers = ['eslint']
" let g:syntastic_elixir_checkers = ['elixir']
" let g:syntastic_enable_elixir_checker = 1
" let g:syntastic_debug = 1
" Mac Clipboard copy and paste
map <leader>- :w! ~/tmp/vimclipboard<cr>:!cat ~/tmp/vimclipboard \| pbcopy<cr><cr>
map <leader>+ :r ~/tmp/vimclipboard<cr>
" http://vim.wikia.com/wiki/Mac_OS_X_clipboard_sharing
set clipboard=unnamed
" Split line, autoformat, autoalign
map <leader>x V:s/\([({[]\)/\1\r/<cr>V:s/\([])}]\)/\r\1/<cr>V%:s/,/,\r/g<cr>jV%=V%:EasyAlign:<cr>
" LESS CSS syntax highlighting
au BufNewFile,BufRead *.less set filetype=less
" Nerdtree toggle
map <leader>d :execute 'NERDTreeToggle ' . getcwd()<CR>
" Gblame
map <leader>gb :Git blame<CR>
" GBrowse
map <leader>gt :GBrowse<CR>
cabbr <expr> %% expand('%:p:h')
" not sure why vim has a problem finding ctags
"let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
" set iskeyword-=_ " not sure if I'll like this...
"map <leader>ct <esc>:!/usr/local/bin/ctags -R<CR>
"autocmd BufWritePost *.rb,*.js silent! !/usr/local/bin/ctags -R &> /dev/null &
" bundle list --paths=true | xargs ctags --extra=+f --exclude=.git --exclude=public --exclude=tmp --exclude=*.js --exclude=log -R *
"set iskeyword+=?
"set iskeyword+=!
map <leader>a :execute "Rg " . expand("<cword>") <CR>
noremap Q gqap
" turn on prose mode for spell checking
command! Prose inoremap <buffer> . .<C-G>u|
\ inoremap <buffer> ! !<C-G>u|
\ inoremap <buffer> ? ?<C-G>u|
\ setlocal spell spelllang=en_us
\ nolist nowrap tw=74 fo=t1 nonu|
\ augroup PROSE|
\ autocmd InsertEnter <buffer> set fo+=a|
\ autocmd InsertLeave <buffer> set fo-=a|
\ augroup END
map <leader>pz :execute "Prose" <CR>
" turn off prose mode
command! Code silent! iunmap <buffer> .|
\ silent! iunmap <buffer> !|
\ silent! iunmap <buffer> ?|
\ setlocal nospell list nowrap
\ tw=74 fo=cqr1 showbreak=…|
\ silent! autocmd! PROSE * <buffer>
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces
map <leader>npz :execute "Code" <CR>
" craxy slow with long lines
" https://superuser.com/questions/302186/vim-scrolls-very-slow-when-a-line-is-too-long
set synmaxcol=120
set ttyfast " u got a fast terminal
" doesn't work with nvim, do I still need it?
" set ttyscroll=3
set lazyredraw " to avoid scrolling problems
set nocursorline
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" Set specific linters
"let g:ale_linters = {
"\ 'javascript': ['eslint'],
"\ 'ruby': ['standardrb', 'rubocop'],
"\}
" Only run linters named in ale_linters settings.
"let g:ale_linters_explicit = 1
let g:airline#extensions#ale#enabled = 1
let g:ale_sign_column_always = 1
"let g:ale_set_highlights = 1
"let g:ale_set_loclist = 0
"let g:ale_set_quickfix = 1
"let g:ale_sign_error = '●'
"let g:ale_sign_warning = '.'
let g:ale_lint_on_save = 1
let g:ale_terraform_terraform_executable = 'terraform'
"let g:ale_linters = {
" \ 'ruby': ['ruby', 'standardrb', 'rubocop'],
" \ 'vim': ['vint'],
" \}
let g:ale_linters = {
\ 'ruby': ['ruby', 'rubocop'],
\ 'vim': ['vint'],
\}
let g:ale_ruby_rubocop_executable = $HOME.'/.rbenv/shims/bundle'
" https://github.com/vim-airline/vim-airline/issues/1845
let g:airline_section_a = '' " hide mode
let g:airline_section_b = '' " hide git branch, it's in my prompt
let g:airline_section_z = '%l:%c ascii:%b' " line:column ascii:code
" https://flowfx.de/blog/teach-vim-rails-about-request-specs/
let g:rails_projections = {
\ "app/controllers/*_controller.rb": {
\ "test": [
\ "spec/controllers/{}_controller_spec.rb",
\ "spec/requests/{}_spec.rb"
\ ],
\ },
\ "spec/requests/*_spec.rb": {
\ "alternate": [
\ "app/controllers/{}_controller.rb",
\ ],
\ }}
" replacing ctrlp with fzf
nmap <C-P> :FZF<CR>
let g:fzf_layout = { 'down': '~40%' }
" clipper like pbcopy that works across ssh
nnoremap <leader>y :call system('socat - UNIX-CLIENT:$HOME/.clipper.sock', @0)<CR>
autocmd TextYankPost * if v:event.operator ==# 'y' | call system('socat - UNIX-CLIENT:$HOME/.clipper.sock', @0) | endif
function! OpenPR(sha)
let pr_number = system("git log --merges --ancestry-path --oneline ". a:sha . "..master | grep 'pull request' | tail -n1 | awk '{print $5}' | cut -c2-")
let remote = fugitive#RemoteUrl(".")
let root = rhubarb#homepage_for_url(remote)
let url = root . '/pull/' . substitute(pr_number, '\v\C\n', '', 1)
call netrw#BrowseX(url, 0)
endfunction
augroup fugitive_ext
autocmd!
" Browse to the commit under my cursor
autocmd FileType fugitiveblame nnoremap <buffer> <leader>gc :execute ":Gbrowse " . expand("<cword>")<cr>
" Browse to the PR for commit under my cursor
autocmd FileType fugitiveblame nnoremap <buffer> <leader>gp :call OpenPR(expand("<cword>"))<cr>
augroup END
map <leader>md :w<cr>:silent! !open -a MacDown % > /dev/null &<cr>:redraw!<cr>
map <leader>cd :Copilot disable<cr>
map <leader>ce :Copilot enable<cr>