-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
375 lines (320 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
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
"Environment tools:
" " Homebrew packages (not necessarily deps for Vim):
" """ ripgrep
" """ task
" """ ctags
" """ ruby
" " Fonts
" """ Adobe Source Code Pro
" """ Fira Mono
"" {{{{ Vim-Plug }}}}
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
"feature extension
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb' " provides :GBrowse
Plug 'tpope/vim-bundler' " provides :Bundle open
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'airblade/vim-gitgutter'
Plug 'kana/vim-textobj-user'
Plug 'kana/vim-textobj-entire' " provides vie, vae, yie, etc.
Plug 'coderifous/textobj-word-column.vim' " provides vic, vac, etc.
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
Plug 'itspriddle/vim-marked'
" Plug 'github/copilot.vim'
" languages
Plug 'sheerun/vim-polyglot'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-rake'
Plug 'ngmy/vim-rubocop' " provides :RuboCop
Plug 'tpope/vim-apathy'
Plug 'mechatroner/rainbow_csv'
Plug 'posva/vim-vue'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Colorschemes
Plug 'owickstrom/vim-colors-paramount'
Plug 'romainl/apprentice'
call plug#end()
"" {{{{ General Settings }}}}
filetype plugin indent on
syntax enable
set re=0
set encoding=utf-8
set history=1000
set nocompatible " no compatibility with legacy vi, required for Vundle
set number " show line numbers
set ruler
set scrolloff=2 " lines displayed above/below cursor
set sessionoptions-=options " don't keep options in sessions
set showcmd " display incomplete commands
set sidescrolloff=5 " keep 5 cols to the left/right of cursor
set tabpagemax=50
set ttimeout
set ttimeoutlen=100
set viminfo^=! " keep capitalized global variables (for plugins)
set wildignore +=**/node_modules/**
set wildmenu
au FocusGained,BufEnter * checktime "like gVim, prompt if file changed
" { CoC }
" https://pragmaticpineapple.com/ultimate-vim-typescript-setup/
set hidden
set nobackup
set nowritebackup
set noswapfile
set cmdheight=2
set updatetime=300
set shortmess+=c
" have switchbuf use open files and open tabs
set switchbuf=useopen,usetab
" needed so vim gets the mouse in tmux
if !has('nvim')
set ttymouse=xterm2
set mouse=a
endif
" smart line joining in comments
if v:version > 703 || v:version == 703 && has('patch541')
set formatoptions+=j
endif
" long line highlighting
" highlight ColorColumn ctermbg=gray
set colorcolumn=80
"" {{{{ Whitespace }}}}
set autoindent " use indent from prev line when starting new line
set nowrap
set tabstop=8 " recommended default, use below settings for 'actual' tabsize
set softtabstop=2
set shiftwidth=2
set smarttab " use shiftwidth (value used in >> cmd) when tabbing
set expandtab " use spaces, not tabs (optional)
set backspace=indent,eol,start " backspace through everything in insert mode
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
"" {{{{ Folding }}}}
set foldmethod=indent
set foldcolumn=0
"" {{{{ Searching }}}}
set hlsearch " highlight matches
set incsearch " incremental searching
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
"" {{{{ statusline, tabline }}}}
set laststatus=2 " always display statusline
set statusline= " clear out for reload
set statusline=%3.3n " buffer number
set statusline+=\ %F%M " full file path + modified flag
set statusline+=\ %L/%l:%c " linetotal/line:col
set statusline+=\ %h%m%r%w " status flags
set statusline+=\ %#warningmsg# " highlight switch
"set statusline+=\ %{SyntasticStatuslineFlag()}
set statusline+=\ %* " highlight exit
set guitablabel= " clear for reload
set guitablabel=%{GuiTabLabel()}
"" {{{{ colorschemes }}}}
"let g:neodark#use_256color = 1 " default: 0
" set termguicolors " for solarized
" set t_Co=256 " for Terminal.app for certain colorschemes
set background=dark
colorscheme apprentice
" highlight Comment cterm=italic gui=italic
"" {{{{ netrw }}}}
let g:netrw_banner = 0 " hide banner
"" {{{{ FZF }}}}
" let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'highlight': 'Todo', 'rounded': v:false } }
" Customize fzf colors to match your color scheme
" - fzf#wrap translates this to a set of `--color` options
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" autocmd FileType javascript JsPreTmpl
" { CoC }
" https://pragmaticpineapple.com/ultimate-vim-typescript-setup/
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("nvim-0.5.0") || has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice.
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
let g:coc_global_extensions = ['coc-tsserver']
" END COC
" Ruby/Rails settings
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
let g:vimrubocop_rubocop_cmd = 'bundle exec rubocop '
"" {{{{ Keymappings }}}}
map <Space> <leader>
"moving pane manipulation over to space-w, easier to use on 40% keyboards
noremap <Leader>w <C-w>
noremap <Leader>e :e **/*
noremap <Leader>h :cd ~/repos/<Cr>
" noremap <Leader>p :cd %:p:h<Cr>
" noremap <Leader>r :s/:\(\w\+\)\(\s*\)=>\s*/\1:\2/g<Cr>
"copy and paste from keyboard
noremap <Leader>y "+y
noremap <Leader>p "+p
noremap <Leader>P "+P
noremap <Leader>v viw"0p
" Scripts
noremap gC :call ToggleVimrc()<Cr>
noremap <Leader>= :call Whitespace()<Cr>
xnoremap <Leader>* :<C-u>call <SID>VSetSearch('/')<CR>/<C-R>=@/<CR><CR>
xnoremap <Leader># :<C-u>call <SID>VSetSearch('?')<CR>?<C-R>=@/<CR><CR>
noremap <Leader>s f"r:;x
" External
"" FZF
noremap <Leader>f :GFiles<Cr>
noremap <Leader>F :Files<Cr>
noremap <Leader>b :Buffers<CR>
noremap <Leader>h :History<CR>
noremap <Leader>/ :Rg<CR>
" noremap <Leader>l :BLines<CR>
" noremap <Leader>L :Lines<CR>
" noremap <Leader>' :Marks<CR>
noremap <Leader>g :grep\<space>
noremap <Leader>G :tabnew +grep\<space>
" grep word under cursor
noremap <Leader>l :grep<space><C-r><C-w><Cr> :copen<Cr>
noremap <Leader>L :tabnew +grep<space><C-r><C-w><Cr> :copen<Cr>
" go to file line in GitHub
noremap <Leader>B :'<,'>GBrowse!<Cr>
" Open alternate file in below split
noremap <Leader>S :sp<Cr>:A<Cr><C-w>J
"Rubocop
noremap <Leader>r :call RunCommandInDir('server', 'RuboCop', '')<Cr>
noremap <Leader>R :call RunCommandInDir('server', 'RuboCop', '-a')<Cr>
" Copilot
" noremap <Leader>c :Copilot panel
"" {{{{ Functions }}}}
command! DiffRuby vert new | set bt=nofile | set syntax=ruby | r ++edit # | 0d_
\ | diffthis | wincmd p | diffthis
function! GuiTabLabel()
let label = ''
let bufnrlist = tabpagebuflist(v:lnum)
" Add '+' if one of the buffers in the tab page is modified
for bufnr in bufnrlist
if getbufvar(bufnr, "&modified")
let label = '+'
break
endif
endfor
" Append the number of windows in the tab page if more than one
let wincount = tabpagewinnr(v:lnum, '$')
if wincount > 1
let label .= wincount
endif
if label != ''
let label .= ' '
endif
" Append the buffer name
return label . bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
endfunction
function! Whitespace() " whitespace and endline cleanup function
if !&binary && &filetype != 'diff'
normal mz
normal Hmy
$put _
%s/\s\+$//e
%s#\($\n\s*\)\+\%$##
$put _
normal 'yz<CR>
normal `z
echo "Whitespace cleanup complete."
endif
endfunction
"" for regex breakdown: http://stackoverflow.com/q/7495932/
" switch to vimrc depending on context
function! ToggleVimrc()
" let s:keep_sb = &switchbuf
" set switchbuf=useopen,usetab
let buffernumber = bufnr("~/.vimrc") " -1 if doesn't exist
let currenttab = tabpagenr() " store current buf as fallback
let buffs_arr = []
tabdo let buffs_arr += tabpagebuflist() " collect all buf#s
" return to current page
exec "tabnext ".currenttab
let i = 0
let bnr = 0
for bnum in buffs_arr " iterate thru buf#s, look for match
let i += 1
if bnum == buffernumber
let bnr = i
endif
endfor
if bufnr("%") == buffernumber "if current buf, close
tabclose
elseif bnr > 0 " if match, switchbuf
sb ~/.vimrc
else " else create buff
$tabnew
e $MYVIMRC
endif
" let &switchbuf=s:keep_sb
" unlet s:keep_sb
endfunction
" Visual-Star
function! s:VSetSearch(cmdtype)
let temp = @s
norm! gv"sy
let @/ = '\V' . substitute(escape(@s, a:cmdtype.'\'), '\n', '\\n', 'g')
let @s = temp
endfunction
" Utility function to run commands in given directory
function! RunCommandInDir(dir, command, args)
let old_dir = getcwd()
execute 'cd' a:dir
let full_command = a:command . (a:args != '' ? ' ' . a:args : '')
execute full_command
execute 'cd' old_dir
endfunction
"" {{{{ Plugin-specific settings }}}}
" {{{ ripgrep }}}
" use ripgrep instead of grep
if executable('rg')
set grepprg=rg\ --vimgrep\ --no-heading\ --smart-case\ --ignore-file\ ~/.rgignore
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
"" {{{{ Last Call }}}}
" set path+=**
set suffixesadd=.html.erb