-
Notifications
You must be signed in to change notification settings - Fork 0
/
_vimrc
335 lines (308 loc) · 10.8 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
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-characterize'
Plug 'tpope/vim-haml'
Plug 'tpope/vim-dispatch'
let g:dispatch_quickfix_height=25
let g:dispatch_tmux_height=25
Plug 'tpope/vim-abolish'
" software capslock: <C-g>c in insert mode
Plug 'tpope/vim-capslock'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-projectionist'
Plug 'vim-scripts/LargeFile'
let g:LargeFile=1.5 "MB
Plug 'yegappan/greplace'
Plug '/opt/homebrew/opt/fzf'
let g:fzf_action = { 'ctrl-t': 'tab split', 'ctrl-o': 'split', 'ctrl-v': 'vsplit' }
let g:fzf_layout = { 'down': '~60%' }
command! FZFMru call fzf#run(fzf#wrap({ 'source': v:oldfiles }))
nnoremap <silent> <C-p> :FZF<CR>
Plug 'AndrewRadev/splitjoin.vim'
Plug 'kana/vim-textobj-entire'
" Arrow keys move visual select blocks
Plug 'zirrostig/vim-schlepp'
vmap <up> <Plug>SchleppUp
vmap <down> <Plug>SchleppDown
vmap <left> <Plug>SchleppLeft
vmap <right> <Plug>SchleppRight
let g:Schlepp#allowSquishingBlock = 1
let g:Schlepp#allowSquishingLines = 1
Plug 'justinmk/vim-gtfo'
Plug 'christoomey/vim-tmux-navigator'
let g:tmux_navigator_no_mappings = 1
noremap <silent> <c-j> :TmuxNavigateDown<cr>
noremap <silent> <c-k> :TmuxNavigateUp<cr>
" Arrow keys resize window
Plug 'talek/obvious-resize'
let g:obvious_resize_default=5
nnoremap <silent> <up> :<C-U>ObviousResizeUp<CR>
nnoremap <silent> <down> :<C-U>ObviousResizeDown<CR>
nnoremap <silent> <left> :<C-U>ObviousResizeLeft<CR>
nnoremap <silent> <right> :<C-U>ObviousResizeRight<CR>
Plug 'https://git.sr.ht/~ackyshake/spacegray.vim'
Plug 'MarcWeber/vim-addon-mw-utils' | Plug 'tomtom/tlib_vim' | Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
Plug 'simplenote-vim/simplenote.vim'
source ~/.simplenoterc
let g:SimplenoteNoteFormat='%N%>[%D]'
let g:SimplenoteStrftime='%Y-%m-%d %H:%M:%S'
Plug 'jeetsukumaran/vim-indentwise'
Plug 'kopischke/vim-fetch' " jump to line/col
Plug 'machakann/vim-highlightedyank'
Plug 'm1foley/vim-expresso'
Plug '~/Code/vim-gus-jump'
Plug 'travisjeffery/vim-auto-mkdir'
Plug 'johngrib/vim-game-code-break'
" Plug 'vim-scripts/Align' | Plug 'vim-scripts/SQLUtilities'
" let g:sqlutil_load_default_maps = 0
" command! -range -nargs=* SQLFormat <line1>,<line2> call SQLUtilities#SQLU_Formatter(<q-args>)
Plug 'uptech/vim-ping-cursor'
let g:ping_cursor_flash_milliseconds = 100
Plug 'tyru/open-browser.vim'
let g:netrw_nogx = 1
nmap gx <Plug>(openbrowser-smart-search)
vmap gx <Plug>(openbrowser-smart-search)
Plug 'markonm/traces.vim' " preview substitutions
" Plug 'idanarye/vim-merginal'
Plug 'vim-test/vim-test'
let test#strategy='dispatch'
Plug 'powerman/vim-plugin-AnsiEsc'
" language-specific plugins
Plug 'dense-analysis/ale'
Plug 'sunaku/vim-ruby-minitest'
Plug 'ck3g/vim-change-hash-syntax'
Plug 'hashivim/vim-terraform'
let g:terraform_fmt_on_save = 1
Plug 'elixir-editors/vim-elixir'
Plug 'mhinz/vim-mix-format'
let g:mix_format_on_save = 1
Plug 'kana/vim-textobj-user' | Plug 'andyl/vim-textobj-elixir'
call plug#end()
set directory=/tmp// "swap files
set backupdir=/tmp,. "tilde files
set statusline=%<%f\ " filename
set statusline+=%-7h " help status
set statusline+=%-4m " modified flag
set statusline+=%-5r " readonly flag
set statusline+=%{fugitive#statusline()}\ " Git status
set statusline+=%=%-14.(%l,%c%V%) " line/column
set statusline+=%30(%=%<%P%) " rulerformat
set number
set ignorecase
set smartcase
set sidescroll=10
set sidescrolloff=2
set lazyredraw
set expandtab
set softtabstop=2
set tabstop=2
set shiftwidth=2
set shiftround
set splitbelow splitright
set winminheight=0
set mousehide
set visualbell
set guioptions=agmrL "disable gui dialogs
set list " display extra whitespace
set synmaxcol=256
set hlsearch
set incsearch
set shortmess=aoOtT
let g:netrw_liststyle=3 " netrw default to tree view
set diffopt+=vertical,internal,algorithm:patience
set printoptions+=header:0
set tags^=./.git/tags; " ctags support
let ruby_minlines = 100
let g:markdown_fenced_languages = ['ruby', 'rb=ruby', 'sh', 'bash=sh', 'javascript', 'js=javascript']
set nofoldenable
set guifont=Monaco:h16
set background=dark
colorscheme spacegray
set grepprg=ag\ --smart-case\ --vimgrep\ --path-to-ignore\ ~/.ignore
set grepformat=%f:%l:%c:%m
function! Grep(...)
" normal/visual mode
if a:0 > 0
" strip accidental newlines from visual mode
let s:grep_term = substitute(a:1, '\n\+$', '', '')
let s:interpret_as_literal = 1
" command-line mode
else
let s:grep_term = ''
let s:interpret_as_literal = 0
endif
if len(s:grep_term) < 3
let s:grep_term = input("Search: ")
let s:interpret_as_literal = 0
endif
if len(s:grep_term) >= 3
if s:interpret_as_literal
let s:grep_term = shellescape(s:grep_term)
let s:grep_term = substitute(s:grep_term, '[|#]', '\\\0', 'g')
execute 'silent grep! -Q --' s:grep_term
else
execute 'silent grep!' s:grep_term
endif
copen
resize 20
endif
redraw!
endfunction
nnoremap <silent> \ :call Grep()<CR>
nnoremap <silent> K :call Grep(expand('<cword>'))<CR>
vnoremap <silent> K "gy :call Grep(@g)<CR>:call setreg('g', [])<CR>
" ale + standardrb
let g:ale_linters = {'ruby': ['standardrb']}
let g:ale_fixers = {'ruby': ['standardrb']}
let g:ruby_indent_assignment_style = 'variable'
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_enter = 'never'
let g:ale_lint_on_insert_leave = 'never'
let g:ale_fix_on_save = 0
let g:ale_lint_on_save = 1
" replace functionality of rubocop.vim
" function! s:RuboCop(args)
" let l:rubocop_cmd = 'bundle exec rubocop --format emacs'
" if len(a:args)
" let l:rubocop_cmd = l:rubocop_cmd . ' ' . a:args
" else
" let l:rubocop_cmd = '(git diff --name-status; git diff --name-status --cached) | grep -v ^D | cut -f 2 | xargs ' . l:rubocop_cmd
" endif
" let l:rubocop_output = system(l:rubocop_cmd)
" let l:rubocop_output = substitute(l:rubocop_output, '\\"', "'", 'g')
" " remove noise from TH projects
" let l:rubocop_output = substitute(l:rubocop_output, 'Warning: unrecognized cop \(Rails\|Style\)\S\+ found in \S\+[\x0]', '', 'g')
" let l:rubocop_output = substitute(l:rubocop_output, '\S\+devforce\S\+: `\S\+` is concealed by line \S\+[\x0]', '', 'g')
" let l:rubocop_output = substitute(l:rubocop_output, '\S\+devforce\S\+: \S\+ has the wrong namespace - should be \S\+[\x0]', '', 'g')
" let l:rubocop_results = split(l:rubocop_output, "\n")
" cexpr l:rubocop_results
" if len(l:rubocop_results)
" copen
" else
" echo 'RuboCop: No offenses detected'
" cclose
" endif
" endfunction
" command! -complete=file -nargs=? RuboCop :call <SID>RuboCop(<q-args>)
" recognize heex extention for Elixir templates
autocmd BufRead,BufNewFile *.html.heex set filetype=eelixir
" quickfix: o opens file in split
augroup quickfix
autocmd!
autocmd FileType qf nnoremap <buffer> o <C-W><CR>
augroup end
" don't open binary files
augroup nonvim
autocmd!
autocmd BufRead *.png,*.jpg,*.pdf,*.gif,*.xls*,*.ppt*,*.doc,*.docx,*.rtf bd! | let &ft=&ft | echoerr "Binary file not opened."
augroup end
" escape ANSI escape sequences in log files
augroup logfile
autocmd!
autocmd BufReadPost *.log :AnsiEsc
augroup end
" make non-ascii chars stand out
autocmd BufReadPost * syntax match nonascii "[^\u0000-\u007F]"
highlight nonascii guibg=Red ctermbg=1 term=standout
" spellcheck git commit messages
autocmd BufRead,BufNewFile COMMIT_EDITMSG set spell
" -o = Don't continue comment when hitting o
" +l = Don't break long lines in insert mode
autocmd FileType * set formatoptions-=o formatoptions+=l
" tcsh-style command line
cnoremap <C-A> <Home>
" cnoremap <C-F> <S-Right>
" cnoremap <C-B> <S-Left>
cnoremap <C-E> <End>
" Typos
cabbrev q1 q!
cabbrev qa1 qa!
nmap Y y$
noremap Q <silent>
noremap ZA :qa!<CR>
" C-e and C-y scroll 3 lines instead of 1
noremap <C-e> 3<C-e>
noremap <C-y> 3<C-y>
" expand %% to current directory in command-line mode
" http://vimcasts.org/episodes/the-edit-command/
cnoremap %% <C-r>=expand('%:h').'/'<CR>
" gp selects last paste
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" <C-L> modified from vim-sensible to ping cursor
nnoremap <silent> <C-L> :nohlsearch<C-R>=has('diff')?'<Bar>diffupdate':''<CR><CR>:PingCursor<CR><C-L>
let g:mapleader=','
" ,c replace until next underscore
nnoremap <Leader>c ct_
" ,a replace until next capital letter
nnoremap <Leader>a c/[A-Z]<CR>
" ,| go to 80th column
nnoremap <Leader><Bar> 80<Bar>
vnoremap <Leader><Bar> 80<Bar>
" ,, open previously edited file
nnoremap <Leader><Leader> <C-^>
" ,<Space> strip all trailing whitespace from current file
nnoremap <Leader><Space> :%s/\s\+$//e<CR>
" ,d diff all
nnoremap <Leader>d :diffthis<CR><C-w><C-w>:diffthis<CR>
" ,D diff off
nnoremap <Leader>D :diffoff<CR><C-w><C-w>:diffoff<CR>
" ,n Simplenote list
nnoremap <Leader>n :SimplenoteList<CR>
" ,y use clipboard register: "+
nnoremap <Leader>y "+
vnoremap <Leader>y "+
" ,<UP> restore arrow keys
nnoremap <silent> <Leader><UP> :nunmap <LT>LEFT>\|nunmap <LT>RIGHT>\|nunmap <LT>DOWN>\|nunmap <LT>UP>\|echo 'Arrow keys restored.'<CR>
" ,p Plug update
nnoremap <Leader>p :PlugUpdate<CR>
" ,5 open current file
nnoremap <Leader>5 :!open %<CR>
" ,L git log -p
nnoremap <Leader>L :Git log -p %<CR>
" ,g Fugitive git status
nnoremap <Leader>g :Git<CR>
" ,j format JSON
nnoremap <Leader>j :%!jq .
" nnoremap <Leader>j :%!python -c "import json, sys, collections; print json.dumps(json.load(sys.stdin, object_pairs_hook=collections.OrderedDict), indent=2)"<CR>:%s/\s\+$//e<CR>:set filetype=json<CR>
" ,f set filetype to ruby
nnoremap <Leader>f :set filetype=ruby<CR>
" ctrl-r ,d in insert/command mode inserts today's date
inoremap <silent> <C-r><Leader>d <C-r>=strftime("%Y-%m-%d")<CR>
cnoremap <C-r><Leader>d <C-r>=strftime("%Y-%m-%d")<CR>
" ,h most recently used files
nnoremap <silent> <Leader>h :FZFMru<CR>
" ,w autopopulate GUS ticket in commit msg
nnoremap <Leader>w /^# Please eO4j/ W-l2yt-{o@0OdipOk
" vim-test mappings
nmap <Leader>t :TestFile<CR>
" TODO: change vim-test options per lanuage
" nmap <Leader>ft :TestFile --max-failures 1<CR>
nmap <Leader>ft :TestFile --fail-fast<CR>
nmap <Leader>s :TestNearest<CR>
nmap <Leader>is :Dispatch iex -S mix test %:<C-r>=line(".")<CR><CR>
" nmap <Leader>fs :TestNearest --max-failures 1<CR>
nmap <Leader>fs :TestNearest --fail-fast<CR>
nmap <Leader>l :TestLast<CR>
" nmap <Leader>fl :TestLast --max-failures 1<CR>
nmap <Leader>fl :TestLast --fail-fast<CR>
autocmd Filetype ruby call LoadRubyMaps()
function! LoadRubyMaps()
set textwidth=80
" vim-rails mappings
nnoremap <Leader>r :Rails<CR>
vnoremap <Leader>r :Rails<CR>
" ,: update Ruby hash syntax
vnoremap <silent> <Leader>: :ChangeHashSyntax<CR>
" ,m memoize a Ruby method
nmap <Leader>m [mwy$oreturn @0 if defined?(@0)jI@0 = l
endfunction