-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
335 lines (277 loc) · 9.05 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
runtime macros/matchit.vim
set number
set showmode
set spell spelllang=en
set history=10000
set noswapfile
set rtp+=/opt/homebrew/opt/fz
set report=0 " Always report changed lines
set autowrite " Save buffer changes to disk
set omnifunc=ale#completion#OmniFunc
set tags=tags;/
set relativenumber
set hlsearch " Highlight search matches
set incsearch " Start searching while typing
set ignorecase " Case insensitive searches...
set smartcase
filetype on
filetype indent on
" remap leader to space
let mapleader = " "
cnoremap %% <C-R>=expand('%:h').'/'<cr>
map <leader>e :edit %%
map <leader>v :view %%
map <leader>m :vsplit %%
map <leader>n :split %%
" split navigation
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Map Ctrl-a h to navigate, so it matches tmux
nnoremap <C-a>h :wincmd h<CR>
nnoremap <C-a>j :wincmd j<CR>
nnoremap <C-a>k :wincmd k<CR>
nnoremap <C-a>l :wincmd l<CR>
autocmd FileType ruby setlocal expandtab shiftwidth=2 tabstop=2
autocmd FileType eruby setlocal expandtab shiftwidth=2 tabstop=2
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
autocmd FileType json,html,yaml set tabstop=2
autocmd FileType typescript setlocal formatprg=prettier\ --parser\ typescript
autocmd FileType go setlocal shiftwidth=2
autocmd FileType go setlocal softtabstop=2
autocmd FileType go setlocal expandtab
" so gf knows about rb files
augroup rubypath
autocmd!
autocmd FileType ruby setlocal suffixesadd+=.rb
augroup END
autocmd FileType ruby setlocal path+=lib
call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')
Plug 'junegunn/vim-easy-align'
Plug 'vim-ruby/vim-ruby'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-unimpaired'
Plug 'preservim/nerdtree'
Plug 'jlanzarotta/bufexplorer'
Plug 'jremmen/vim-ripgrep'
Plug 'dense-analysis/ale'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'ayu-theme/ayu-vim'
Plug 'itchyny/lightline.vim'
Plug 'vim-test/vim-test'
Plug 'jacoborus/tender.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' }
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.6' }
call plug#end()
" tender plugin
if (has("termguicolors"))
set termguicolors
endif
syntax enable
colorscheme tender
function! GitStatus()
let [a,m,r] = GitGutterGetHunkSummary()
return printf('+%d ~%d -%d', a, m, r)
endfunction
let g:rg_highlight = 1
let g:LanguageClient_serverCommands = {
\ 'ruby': ['~/.rbenv/shims/solargraph'],
\ }
" ctrlP
set runtimepath^=~/.vim/bundle/ctrlp.vim
" RSPEC
let g:test#preserve_screen = 1
let g:test#vim#term_position = "belowright"
let test#ruby#rspec#executable = 'DISABLE_SPRING=true bin/rspec --format documentation --color'
let test#enabled_runners = ["ruby#rspec"]
let test#strategy = "neovim"
" SEARCH
hi Search guibg=peru guifg=wheat
set wildignore+=*.so
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem
set wildignore+=*.gif,*.jpg,*.png,*.log
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle
set wildignore+=*.swp,*~,._*
set wildignore+=.DS_Store
"Bd will behave like bd but preserve the split buffer window
command Bd bp\|bd \#
" When editing a file, always jump to the last known cursor position.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
if executable('rg')
set grepprg=rg\ --color=never\ --vimgrep\ --no-heading\ --smart-case
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
endif
if executable('fzf')
set rtp+=/usr/local/opt/fzf
endif
" Keymaps
" Use Cmd+k / Cmd+j to jump between linter failures
nmap <silent> <D-k> <Plug>(ale_previous)
nmap <silent> <D-j> <Plug>(ale_next)
" Use Enter to lint
nnoremap <silent><cr> :nohlsearch<cr>:ALELint<cr>
" Map Ctrl + p to open fuzzy find (FZF)
nnoremap <c-p> :Files<cr>
map <Leader>q :split ~/Documents/notes.md<cr>
" remap test commands
nmap <silent> <leader>t :TestNearest<CR>
nmap <silent> <leader>T :TestFile<CR>
" unhighlight search
map <leader>h :noh<CR>
" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
" Linters
let g:ale_linters = {
\ 'javascript': ['prettier'],
\ 'json': ['jsonlint'],
\ 'markdown': ['prettier'],
\ 'eruby': ['erblint'],
\ 'ruby': ['rubocop'],
\ 'go': ['gopls']
\ }
let g:ale_fixers = {
\ 'css': ['prettier'],
\ 'javascript': ['prettier'],
\ 'markdown': ['prettier'],
\ 'ruby': ['rubocop'],
\ 'yaml': ['prettier'],
\ 'html': ['prettier'],
\ '*': ['remove_trailing_lines', 'trim_whitespace']
\ }
" Visual
let g:ale_fix_on_save = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%s'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_sign_error = '❌'
let g:ale_sign_warning = '⚠️'
let g:ale_statusline_format = ['❌%d', '⚠️ %d', '']
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 0
let g:ale_completion_enabled = 1
" JS
" let b:ale_fixers = ['prettier']
" let g:ale_lint_on_text_changed = 0
" Rubocop
let g:ale_ruby_rubocop_auto_correct_all = 1
let g:ale_ruby_rubocop_executable = "bundle"
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
" Smart tab autocomplete behavior
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
" Ruby
let g:ruby_indent_assignment_style = 'variable'
let g:ruby_indent_block_style = 'do'
" Status
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '✨ all good ✨' : printf(
\ '😞 %dW %dE',
\ all_non_errors,
\ all_errors
\)
endfunction
set statusline=
set statusline+=%m
set statusline+=\ %f
set statusline+=\ %q
set statusline+=%=
set statusline+=%y
set statusline+=\ %c,
set statusline+=%l/%L
set statusline+=\ %{LinterStatus()}
set statusline=%{FugitiveStatusline()}
" set statusline+=%{GitStatus()}
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" faster for saves
nmap <leader>w :w!<cr>
" Fuzzy search
" Use The Silver Searcher https://github.com/ggreer/the_silver_searcher
if executable('ag')
" Use Ag over Grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in fzf for listing files. Lightning fast and respects .gitignore
let $FZF_DEFAULT_COMMAND = 'ag --literal --files-with-matches --nocolor --hidden -g ""'
endif
" NerdTree
map <leader>- :NERDTreeToggle<CR>
map <leader>r :NERDTreeFind<cr>
" highlight where file is in tree
map ] :NERDTreeFind<CR>
let g:NERDTreeWinPos = "left"
let g:NERDTreeWinSize = 40
let g:NERDTreeMinimalMenu=1
" keep open after :bd
nnoremap \d :bp<cr>:bd #<cr>
" If another buffer tries to replace NERDTree, put it in the other window, and bring back NERDTree.
autocmd BufEnter * if bufname('#') =~ 'NERD_tree_\d\+' && bufname('%') !~ 'NERD_tree_\d\+' && winnr('$') > 1 |
\ let buf=bufnr() | buffer# | execute "normal! \<C-W>w" | execute 'buffer'.buf | endif
" Lightline
let g:lightline = {
\ 'colorscheme': 'tender',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'gitbranch': 'FugitiveHead'
\ },
\ }
" Fugitive Conflict Resolution
nnoremap <leader>gd :Gvdiff<CR>
nnoremap gdh :diffget //2<CR>
nnoremap gdl :diffget //3<CR>
" Fugitive
map <Leader><Leader>c :Git commit<cr>
map <Leader><Leader>b :Git blame<cr>
map <Leader><Leader>s :Git status<cr>
map <Leader><Leader>w :Git write<cr>
map <Leader><Leader>p :Git push<cr>
map <Leader><Leader>f :Git fetch<cr>
map <Leader><Leader>u :Git up<cr>
" Map \p to promote variable assignment to let in rspec
map <leader>p :call PromoteToLet()<cr>
function! PromoteToLet()
:normal! dd
:exec '?^\s*describe\|fdescribe\|fcontext\|context\|RSpec\.describe\>'
:normal! p
:.s/\(\w\+\)\s\+=\s\+\(.*\)$/let(:\1) { \2 }/
:normal ==
endfunction
" COC lsp additional settings
nmap gd <Plug>(coc-definition)
nmap K <Plug>(coc-hover)
" remap to confirm completion
inoremap <expr> <cr> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"
inoremap <silent><expr> <cr> coc#pum#visible() ? coc#_select_confirm() : "\<C-g>u\<CR>"
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif