forked from square/maximum-awesome
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvimrc
591 lines (512 loc) · 19.2 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
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
" don't bother with vi compatibility
set nocompatible
filetype plugin on
" enable syntax highlighting
syntax enable
let g:node_host_prog = '~/.nvm/versions/node/v16.13.1/bin/node'
let g:coc_node_path = '~/.nvm/versions/node/v16.13.1/bin/node'
let g:node_host_prog = '~/.nvm/versions/node/v16.13.1/lib/node_modules'
" configure Vundle
filetype on " without this vim emits a zero exit status, later, because of :ft off
:filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" install Vundle bundles
if filereadable(expand("~/.vimrc.bundles"))
source ~/.vimrc.bundles
source ~/.vimrc.bundles.local
endif
call vundle#end()
" ensure ftdetect et al work by including this after the Vundle stuff
filetype plugin indent on
set autoindent
set autoread " reload files when changed on disk, i.e. via `git checkout`
set backspace=2 " Fix broken backspace in some setups
set backupcopy=yes " see :help crontab
set clipboard=unnamed " yank and paste with the system clipboard
set directory-=. " don't store swapfiles in the current directory
set encoding=utf-8
set expandtab " expand tabs to spaces
set ignorecase " case-insensitive search
set incsearch " search as you type
set laststatus=2 " always show statusline
set list " show trailing whitespace
set listchars=tab:▸\ ,trail:•
set number " show line numbers
set ruler " show where you are
set scrolloff=3 " show context above/below cursorline
set shiftwidth=2 " normal mode indentation commands use 2 spaces
set showcmd
set smartcase " case-sensitive search if any caps
set softtabstop=2 " insert mode tab and backspace use 2 spaces
set tabstop=2
set wildignore=log/**,node_modules/**,target/**,tmp/**,*.rbc
set wildmenu " show a navigable menu for tab completion
set wildmode=longest,list,full
" Enable basic mouse behavior such as resizing buffers.
set mouse=a
if exists('$TMUX') && !has('nvim') " Support resizing in tmux
set ttymouse=xterm2
endif
" keyboard shortcuts
let mapleader = ','
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
noremap <leader>l :Align
" nnoremap <leader>a :Ag<space>
" nnoremap <leader>b :CtrlPBuffer<CR>
" nnoremap <leader>d :NERDTreeToggle<CR>
" nnoremap <leader>f :NERDTreeFind<CR>
nnoremap <leader>a :<C-u>CocList grep<cr>
nnoremap <leader>b :<C-u>CocList -A buffers<cr>
nnoremap <leader>d :CocCommand explorer --toggle<CR>
nnoremap <leader>[ :CocCommand explorer --toggle<CR>
function! FocusInExplorer()
let l:a = 0
for window in getwininfo()
if getbufvar(window.bufnr, '&ft') == 'coc-explorer'
let l:a = 1
break
endif
endfor
if l:a == 1
call CocActionAsync('runCommand', 'explorer.doAction', 'closest', ['reveal:0'], [['relative', 0, 'file']])
execute 'CocCommand explorer --no-toggle'
else
execute 'CocCommand explorer --reveal '.expand('%:p')
endif
endfunction
nmap <Leader>f :call FocusInExplorer()<CR>
" nnoremap <leader>t :CtrlP<CR>
" nnoremap <leader>T :CtrlPClearCache<CR>:CtrlP<CR>
nnoremap <leader>t :<C-u>CocList -A files<cr>
nnoremap <leader>] :CocOutline<CR>
nnoremap <silent> <space>y :<C-u>CocList -A --normal yank<cr>
nnoremap <leader><space> :call whitespace#strip_trailing()<CR>
" nnoremap <leader>g :GitGutterToggle<CR>
noremap <silent> <leader>V :source ~/.vimrc<CR>:filetype detect<CR>:exe ":echo 'vimrc reloaded'"<CR>
noremap <leader>j <esc>
set background=dark
" in case you forgot to sudo
cnoremap w!! %!sudo tee > /dev/null %
" plugin settings
let g:ctrlp_match_window = 'order:ttb,max:20'
" let g:NERDSpaceDelims = 1
let g:gitgutter_enabled = 1
" Use The Silver Searcher https://github.com/ggreer/the_silver_searcher
" if executable('ag')
" " Use Ag over Grep
" set grepprg=ag\ --nogroup
"
" " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
" let g:ctrlp_user_command = 'ag %s -l -g ""'
" endif
" fdoc is yaml
autocmd BufRead,BufNewFile *.fdoc set filetype=yaml
" md is markdown
autocmd BufRead,BufNewFile *.md set filetype=markdown
autocmd BufRead,BufNewFile *.md set spell
" extra rails.vim help
let g:rails_projections = {
\ "app/uploaders/*_uploader.rb": {
\ "command": "uploader",
\ "template":
\ ["class {camelcase|capitalize|colons}Uploader < "
\ . "CarrierWave::Uploader::Base", "end"],
\ "test": [
\ "test/unit/{}_uploader_test.rb",
\ "spec/models/{}_uploader_spec.rb"
\ ],
\ "rubyMacro": ["process", "version"]
\ },
\ "features/support/*.rb": {"command": "support"},
\ "features/support/env.rb": {"command": "support"},
\ "spec/factories/*_factory.rb": {"command": "factory"},
\ "app/jobs/*.rb": {"command": "job"},
\ "app/javascript/components/*.*": {"command": "component"}
\ }
" automatically rebalance windows on vim resize
autocmd VimResized * :wincmd =
" Fix Cursor in TMUX
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
" Don't copy the contents of an overwritten selection.
vnoremap p "_dP
" Go crazy!
if filereadable(expand("~/.vimrc.local"))
" In your .vimrc.local, you might like:
"
" set autowrite
" set nocursorline
" set nowritebackup
" set whichwrap+=<,>,h,l,[,] " Wrap arrow keys between lines
"
" autocmd! bufwritepost .vimrc source ~/.vimrc
source ~/.vimrc.local
endif
" Colors
if !has('nvim')
set term=xterm-256color
endif
let g:solarized_termcolors=256
let g:lightline = {
\ 'colorscheme': 'tokyonight',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'coc_info', 'coc_hints', 'coc_errors', 'coc_warnings', 'coc_ok' ], [ 'coc_status' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead'
\ },
\ }
call lightline#coc#register()
" let g:NERDTreeIgnore = ['^build$', '^dist$', '^node_modules$']
let g:webdevicons_enable = 1
" let g:webdevicons_enable_nerdtree = 1
let g:webdevicons_enable_lightline = 1
let g:webdevicons_enable_ctrlp = 1
let g:WebDevIconsTabAirLineAfterGlyphPadding = ' '
let g:context_highlight_normal = 'NormalFloat'
let g:context_highlight_border = 'Comment'
let g:context_highlight_tag = 'Special'
let g:context_nvim_no_redraw = 1
function! SetupTokyo()
lua << EOF
require("tokyonight").setup({
style = "night",
italic_functions = true,
sidebars = { "qf", "vista_kind", "terminal", "packer", "nerdtree", "ctrlp", "tagbar", "coc", "context.vim", "coctree", "coc-explorer", "qf", "treesitter", "treesitter-context" }
})
EOF
endfunction
call SetupTokyo()
colorscheme tokyonight
let g:indentLine_char = ''
" Emmet
let g:user_emmet_settings = {
\ 'javascript.jsx' : {
\ 'extends' : 'jsx',
\ },
\ 'javascript.tsx' : {
\ 'extends' : 'jsx',
\ },
\}
" Vim Tabs / Buffer Barbar
" map <C-t> :tabnew<CR>
nnoremap <silent> <space>, :BufferPrevious<CR>
nnoremap <silent> <space>< :BufferMovePrevious<CR>
" nnoremap <silent> gT :BufferPrevious<CR>
nnoremap <silent> <space>. :BufferNext<CR>
nnoremap <silent> <space>> :BufferMoveNext<CR>
" nnoremap <silent> gt :BufferNext<CR>
nnoremap <silent> <space>p :BufferPin<CR>
nnoremap <silent> <space>n :enew<CR>
" map <C-t> :enew<CR>
nnoremap <silent> <space>x :BufferClose<CR>
nnoremap <silent> <space>X :Bdelete! this<CR>
nnoremap <silent> <space><space> :BufferPick<CR>
nnoremap <silent> <space>q :BufferCloseAllButCurrentOrPinned<CR>
nnoremap <silent> <space>t :terminal<CR>
" Syntastic
" let g:syntastic_ruby_checkers = ['rubocop', 'mri']
" let g:syntastic_javascript_checkers = ['eslint']
" let g:syntastic_check_on_open = 0
" Neomake
" function! MyOnBattery()
" if has('macunix')
" return match(system('pmset -g batt'), "Now drawing from 'Battery Power'") != -1
" elseif has('unix')
" return readfile('/sys/class/power_supply/AC/online') == ['0']
" endif
" return 0
" endfunction
"
" if MyOnBattery()
" call neomake#configure#automake('w')
" else
" call neomake#configure#automake('nw', 1000)
" endif
" nvim.coc
" if hidden is not set, TextEdit might fail.
set hidden
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
inoremap <silent><expr> <C-j> coc#pum#visible() ? coc#pum#next(1) : "\<Down>"
inoremap <silent><expr> <C-k> coc#pum#visible() ? coc#pum#prev(1) : "\<Up>"
" Use tab for trigger completion with characters ahead and navigate.
function! CheckBackSpace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ?
\ "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ CheckBackSpace() ? "\<TAB>" :
\ coc#refresh()
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#_select_confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
let g:coc_snippet_next = '<tab>'
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocActionAsync('doHover')
endif
endfunction
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
" Remap for format selected region
xmap <leader>sf <Plug>(coc-format-selected)
nmap <leader>sf <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocActionAsync('formatSelected')
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Remap for do codeAction of selected region, ex: `<leader>aap` for current paragraph
xmap <leader>ca <Plug>(coc-codeaction-selected)
nmap <leader>ca <Plug>(coc-codeaction-selected)
" Remap for do codeAction of current line
nmap <leader>cac <Plug>(coc-codeaction)
" Fix autofix problem of current line
nmap <leader>qf <Plug>(coc-fix-current)
" Create mappings for function text object, requires document symbols feature of languageserver.
xmap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap if <Plug>(coc-funcobj-i)
omap af <Plug>(coc-funcobj-a)
" Use <TAB> for select selections ranges, needs server support, like: coc-tsserver, coc-python
nmap <silent> <TAB> <Plug>(coc-range-select)
xmap <silent> <TAB> <Plug>(coc-range-select)
" Use `:Format` to format current buffer
command! -nargs=0 Format :call CocActionAsync('format')
" Use `:Fold` to fold current buffer
command! -nargs=? Fold :call CocActionAsync('fold', <f-args>)
" use `:OR` for organize import of current buffer
command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')
command! -nargs=0 Rspec :Dispatch bundle exec rspec %
" Add status line support, for integration with other plugin, checkout `:h coc-status`
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Using CocList
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>r :<C-u>CocListResume<CR>
nnoremap <silent> <space>l :<C-u>CocList<CR>
nmap <expr> <silent> <C-s> <SID>select_current_word()
function! s:select_current_word()
if !get(g:, 'coc_cursors_activated', 0)
return "\<Plug>(coc-cursors-word)"
endif
return "*\<Plug>(coc-cursors-word):nohlsearch\<CR>"
endfunc
command! -nargs=0 Prettier :CocCommand prettier.formatFile
" Goyo
" let g:limelight_conceal_ctermfg = 240
" function! s:goyo_enter()
" if executable('tmux') && strlen($TMUX)
" silent !tmux set status off
" silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
" endif
" set noshowmode
" set noshowcmd
" set scrolloff=999
" set linebreak!
" Limelight
" endfunction
" function! s:goyo_leave()
" if executable('tmux') && strlen($TMUX)
" silent !tmux set status on
" silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
" endif
" set showmode
" set showcmd
" set scrolloff=5
" set linebreak!
" Limelight!
" endfunction
" autocmd! User GoyoEnter nested call <SID>goyo_enter()
" autocmd! User GoyoLeave nested call <SID>goyo_leave()
" noremap <leader>p :Goyo<CR>
" noremap <leader>P :Limelight!!<CR>
function! DeleteFileSwaps()
write
let l:output = ''
redir => l:output
silent exec ':sw'
redir END
let l:current_swap_file = substitute(l:output, '\n', '', '')
let l:base = substitute(l:current_swap_file, '\v\.\w+$', '', '')
let l:swap_files = split(glob(l:base.'\.s*'))
" delete all except the current swap file
for l:swap_file in l:swap_files
if !empty(glob(l:swap_file)) && l:swap_file != l:current_swap_file
call delete(l:swap_file)
echo "swap file removed: ".l:swap_file
endif
endfor
" Reset swap file extension to `.swp`.
set swf! | set swf!
echo "Reset swap file extension for file: ".expand('%')
endfunction
command! DeleteFileSwaps :call DeleteFileSwaps()
command! ReloadConfiguration :source ~/.vimrc
highlight clear SignColumn
autocmd FileType html,css,scss,hml,haml,vue,slim,erb,jsx set iskeyword=@,48-57,_,-,?,!,192-255
autocmd FileType scss setl iskeyword+=@-@
let g:jsdoc_formatter = 'tsdoc'
let g:coc_node_path = "~/.nvm/versions/node/v14.15.0/bin/node"
augroup vimrc
au BufReadPre * setlocal foldmethod=syntax
au BufWinEnter * if &fdm == 'indent' | setlocal foldmethod=manual | endif
augroup END
set nofoldenable
set foldlevelstart=2
nnoremap <leader>ga :Git add .<CR>
command -nargs=* Ga :Git add <args>
nnoremap <leader>gc :Git commit<CR>
command! -nargs=0 Gc :Git commit
nnoremap <leader>gp :Git -c push.default=current push<CR>
command! -nargs=0 Gp :Git -c push.default=current push
nnoremap <leader>gs :Git<CR>
command! -nargs=? Gco :Git checkout <args>
command! -nargs=0 Gdt :Git dt
command! -nargs=0 Ggpull :Git -c pull.default=current pull
command! -nargs=0 Gsweep :Git sweep
command! -nargs=0 Gpr :Start gh pr create
command! -nargs=0 Gprw :Dispatch gh pr view --web
command! -nargs=0 Gprc :Start gh pr view --comments
command! -nargs=0 Gprs :Dispatch gh pr status
command! -nargs=0 Gprm :Dispatch gprm
" nmap <Leader>ga <Plug>(GitGutterStageHunk) " git add (chunk)
" nmap <Leader>gu <Plug>(GitGutterUndoHunk) " git undo (chunk)
" Jump between hunks
" nmap <Leader>gn <Plug>(GitGutterNextHunk) " git next
" nmap <Leader>gp <Plug>(GitGutterPrevHunk) " git previous
let g:UltiSnipsExpandTrigger="<Nul>"
let g:UltiSnipsJumpForwardTrigger="<Nul>"
let g:UltiSnipsJumpBackwardTrigger="<Nul>"
let g:python_host_prog = '/opt/homebrew/bin/python'
let g:python_host_skip_check=1
let g:python3_host_prog = '/opt/homebrew/bin/python3'
let g:python3_host_skip_check=1
let g:coc_node_path = "/Users/ajdubovoy/.nvm/versions/node/v16.13.1/bin/node"
let g:copilot_node_command = "/Users/ajdubovoy/.nvm/versions/node/v16.13.1/bin/node"
:tnoremap <Esc><Esc> <C-\><C-n>
autocmd TermOpen * startinsert
fun! SetupCommandAlias(from, to)
exec 'cnoreabbrev <expr> '.a:from
\ .' ((getcmdtype() is# ":" && getcmdline() is# "'.a:from.'")'
\ .'? ("'.a:to.'") : ("'.a:from.'"))'
endfun
call SetupCommandAlias("!","Dispatch")
set shell=zsh\ -i
let g:vim_vue_plugin_config = {
\'syntax': {
\ 'template': ['html', 'pug'],
\ 'script': ['javascript'],
\ 'style': ['css'],
\},
\'full_syntax': [],
\'initial_indent': [],
\'attribute': 0,
\'keyword': 0,
\'foldexpr': 0,
\'debug': 0,
\}
lua << EOF
require'nvim-treesitter'.setup {
-- A list of parser names, or "all"
ensure_installed = { "html", "css", "javascript", "ruby" },
}
require'treesitter-context'.setup {
highlight = {
enable = true
},
rainbow = {
enable = true,
extended_mode = true, -- Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean
},
textobjects = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
-- you can optionally set descriptions to the mappings (used in the desc parameter of nvim_buf_set_keymap
["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
},
-- You can choose the select mode (default is charwise 'v')
selection_modes = {
['@parameter.outer'] = 'v', -- charwise
['@function.outer'] = 'V', -- linewise
['@class.outer'] = '<c-v>', -- blockwise
},
-- If you set this to `true` (default is `false`) then any textobject is
-- extended to include preceding xor succeeding whitespace. Succeeding
-- whitespace has priority in order to act similarly to eg the built-in
-- `ap`.
include_surrounding_whitespace = true,
},
refactor = {
highlight_definitions = {
enable = true,
clear_on_cursor_move = true,
highlight_current_scope = { enable = true },
smart_rename = {
ekable = true,
keymaps = {
smart_rename = "rr",
},
},
},
},
}
EOF