-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvimrc
More file actions
362 lines (331 loc) · 14.4 KB
/
vimrc
File metadata and controls
362 lines (331 loc) · 14.4 KB
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
""
"" Basic Setup
""
"" See https://github.com/carlhuda/janus/blob/60e6864fbd60dc8efa9dc4c6de40b7615452814c/janus/vim/core/before/plugin/settings.vim
if has('vim_starting') && !has('nvim') && &compatible
set nocompatible " Be iMproved
endif
set number " Show line numbers
set ruler " Show line and column number
syntax enable " Turn on syntax highlighting allowing local overrides
set hidden " Allow switching buffers with unsaved changes in the current one
" Neovim disallow changing 'enconding' option after initialization
" see https://github.com/neovim/neovim/pull/2929 for more details
if !has('nvim')
set encoding=utf-8 " Set default encoding to UTF-8
endif
""
"" Whitespace
""
set nowrap " don't wrap lines
set tabstop=2 " a tab is two spaces
set shiftwidth=2 " an autoindent (with <<) is two spaces
set expandtab " use spaces, not tabs
set list " Show invisible characters
set backspace=indent,eol,start " backspace through everything in insert mode
if exists("g:enable_mvim_shift_arrow")
let macvim_hig_shift_movement = 1 " mvim shift-arrow-keys
endif
" List chars
set listchars="" " Reset the listchars
set listchars=tab:\ \ " a tab should display as " ", trailing whitespace as "."
set listchars+=trail:. " show trailing spaces as dots
set listchars+=extends:> " The character to show in the last column when wrap is
" off and the line continues beyond the right of the screen
set listchars+=precedes:< " The character to show in the last column when wrap is
"" https://github.com/ntpeters/vim-better-whitespace
let g:better_whitespace_enabled=1
let g:strip_whitespace_on_save=1
let g:strip_whitespace_confirm=0
"let g:ale_fixers['*'] = ['remove_trailing_lines', 'trim_whitespace']
""
"" 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
""
"" Wild settings
""
" These make auto-complete work like it does in bash (only to the ambiguity)
set wildmenu
set wildmode=list:longest
" Disable output and VCS files
set wildignore+=*.o,*.out,*.obj,.git,*.rbc,*.rbo,*.class,.svn,*.gem
" Disable archive files
set wildignore+=*.zip,*.tar.gz,*.tar.bz2,*.rar,*.tar.xz
" Ignore bundler and sass cache
set wildignore+=*/vendor/gems/*,*/vendor/cache/*,*/.bundle/*,*/.sass-cache/*
" Disable temp and backup files
set wildignore+=*.swp,*~,._*
""
"" Backup and swap files
""
set backupdir^=~/.vim/_backup// " where to put backup files.
set directory^=~/.vim/_temp// " where to put swap files.
""
"" Status line
""
" Useful status information at bottom of screen
set laststatus=2 " always show the status bar
set statusline=[%n]\ " Buffer number
set statusline+=%<%.99f\ " File name (relative to current path)
set statusline+=%h%w%m%r%y " help, preview, modified, readonly, filetype
set statusline+=\ -\ %{fugitive#statusline()} " Add in git information from fugitive
" ALE Status Line
" https://github.com/dense-analysis/ale#custom-statusline
function! ALEStatuslineHelper(type, colored) abort
let l:counts = ale#statusline#Count(bufnr(''))
if a:type == 'warnings'
let l:count = l:counts.total - (l:counts.error + l:counts.style_error)
let l:label = 'W'
elseif a:type == 'errors'
let l:count = l:counts.error + l:counts.style_error
let l:label = 'E'
endif
"if (l:warnings == 0 && !a:colored) || (l:warnings != 0 && a:colored)
if (!l:count && !a:colored) || (l:count && a:colored)
return printf('%d%s', l:count, l:label)
else
return ''
endif
endfunction
set statusline+=\ -\ [
set statusline+=%{ALEStatuslineHelper('warnings',0)}
set statusline+=%#ALEWarningSign#%{ALEStatuslineHelper('warnings',1)}%*
set statusline+=\ " space
set statusline+=%{ALEStatuslineHelper('errors',0)}
set statusline+=%#ALEWarningSign#%{ALEStatuslineHelper('errors',1)}%*
set statusline+=]
" END: ALE Status Line
set statusline+=%=[\%05b\:0x\%04B]\ %-16(\ %l,%c\ %) " byte value, byte value (hex), line number, column number
set statusline+=%L/%P " total lines, percentage of file
" Folding settings
set foldmethod=indent " fold based on indent
set foldnestmax=5 " deepest fold levels
set foldenable " fold by default
set foldlevel=3 " start on methods for normal class
" Solarized
" With black light (pallet color 8) set to #0387AD we need to set termtrans:
" https://github.com/altercation/solarized/issues/220#issuecomment-269930034
let g:solarized_termtrans = 1
set background=dark
colorscheme solarized
" undercurl support
let &t_Cs = "\e[4:3m"
let &t_Ce = "\e[4:0m"
" vim-gitgutter color settings
" See https://github.com/airblade/vim-gitgutter/commit/8db2fc5da0d5ad02fa4fa38ae16dc2fad9bfd201
highlight! link SignColumn LineNr
highlight! link GitGutterAdd LineNr
highlight! link GitGutterChange LineNr
highlight! link GitGutterDelete LineNr
" highlight GitGutterAdd guibg=#073642 ctermbg=0
" highlight GitGutterChange guibg=#073642 ctermbg=0
" highlight GitGutterDelete guibg=#073642 ctermbg=0
" highlight SignColumn guibg=#073642 ctermbg=0
" Spell check
set spelllang=en
set spellfile=$HOME/.spell/en.utf-8.add
" TODO(ppg): how to get undercurl to be red?
highlight SpellBad gui=undercurl guisp=red term=undercurl cterm=undercurl
autocmd FileType cucumber setlocal spell
autocmd FileType gitcommit setlocal spell
autocmd FileType markdown setlocal spell
autocmd FileType text setlocal spell
" ALE
" https://github.com/dense-analysis/ale#how-can-i-disable-virtual-text-appearing-at-ends-of-lines
let g:ale_virtualtext_cursor = 'disabled'
" https://github.com/dense-analysis/ale#how-can-i-use-the-quickfix-list-instead-of-the-loclist
"let g:ale_set_loclist = 0
"let g:ale_set_quickfix = 1
" https://github.com/dense-analysis/ale#how-can-i-change-the-format-for-echo-messages
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%] %[code]%'
let g:ale_fix_on_save = 1
let g:ale_fixers = {}
" Default python:
" \ 'python': ['flake8', 'mypy', 'pylint', 'pyright', 'ruff']
" - disable pyright as not configured and too noisy
" Tell ALE to use cli2 instead of the older cli
let g:ale_linters = {
\ 'go': ['gofmt', 'golangci-lint', 'gopls', 'govet'],
\ 'markdown': ['markdownlint-cli2'],
\ 'python': ['flake8', 'mypy', 'pylint', 'ruff']
\}
" Map bracket e|E to move between errors
:nmap ]e :ALENextWrap<CR>
:nmap [e :ALEPreviousWrap<CR>
:nmap ]E :ALELast<CR>
:nmap [E :ALEFirst<CR>
" map for cnext and cprevious
" FIXME(ppg): should :lnext and :lprevious be ALENext and ALEPrevious?
nnoremap <silent> <leader>] :lnext<CR>
nnoremap <silent> <leader>[ :lprevious<CR>
" Copilot
packadd! copilot.vim
:imap <silent> <C-j> <Plug>(copilot-next)
:imap <silent> <C-k> <Plug>(copilot-previous)
:imap <silent> <C-\> <Plug>(copilot-dismiss)
" FIXME(ppg): how to adjust the colors here?
autocmd ColorScheme solarized highlight CopilotSuggestion guifg=#555500 ctermfg=5 guibg=#073642 ctermbg=0
" Ruby
let g:syntastic_ruby_checkers = ['mri', 'rubocop']
let g:syntastic_ruby_rubocop_args = '--display-cop-names --display-style-guide'
" Stop printing out warnings for <%= some_var_here %>
let g:syntastic_eruby_ruby_quiet_messages = { 'regex': 'possibly useless use of a variable in void context' }
" Go
" Turn on gopls
let g:go_gopls_options = ['-remote=auto']
" Disable the 'composites' analyzer (likely tied to 'efaceany')
let g:ale_go_gopls_init_options = {'ui.diagnostic.analyses': {
\ 'efaceany': v:false,
\ }}
" Enable for debug
"let g:go_gopls_options = ['-remote=auto', '-logfile=auto', '-debug=:0', '-remote.debug=:0', '-rpc.trace']
let g:go_def_mode = 'gopls'
let g:go_info_mode = 'gopls'
set updatetime=100
"let g:go_auto_type_info = 1 " shows type info at bottom when on something
let g:go_auto_sameids = 1 " highlights the same variables when cursor is there
" Support :A
" https://github.com/fatih/vim-go/wiki/Tutorial#vimrc-improvements-5
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
" https://github.com/fatih/vim-go/wiki/Tutorial#identifier-resolution
" autocmd FileType go nmap <Leader>i <Plug>(go-info)
let g:go_build_tags = "acceptance benchmark functional integration client_test"
let g:go_fmt_fail_silently = 1 " let ALE show compile errors instead of opening location list
" Go Linting
let g:ale_go_gobuild_options = "-tags 'acceptance benchmark functional integration client_test'"
let g:ale_go_gofmt_options = "-tags 'acceptance benchmark functional integration client_test'"
let g:ale_go_golangci_lint_package = 1
" disable --enable-all default to defer to local .golangci.yml file
let g:ale_go_golangci_lint_options = "--build-tags 'acceptance benchmark functional integration devci client_test'"
let g:ale_go_govet_options = "-tags 'acceptance benchmark functional integration client_test'"
" Go - ginkgo
autocmd BufNewFile,BufReadPost *_test.go set filetype=ginkgo.go
" JavaScript
" Python
" https://github.com/dense-analysis/ale/blob/v3.3.0/doc/ale-python.txt#L14-L20
let g:ale_python_auto_poetry = 1
" https://black.readthedocs.io/en/stable/integrations/editors.html#with-ale
let g:ale_fixers.python = ['black', 'isort']
let g:black_quiet = 1
"let g:vim_isort_python_version = 'python'
autocmd BufRead,BufNewFile *.py set textwidth=88
" waiting on https://github.com/psf/black/pull/1733 to be released
" workaround: https://github.com/psf/black/issues/252
"autocmd BufWritePre *.py silent! execute ':Black'
" autocmd BufWritePre *.py execute ':Isort'
"" TODO(ppg): try to get this working
"" Enable python-language-server
"if executable('pyls')
"# Set these to default enum value
" au User lsp_setup call lsp#register_server({
" \ 'name': 'pyls',
" \ 'cmd': {server_info->['pyls']},
" \ 'whitelist': ['python'],
" \ 'workspace_config': {'pyls': {'plugins': {'black': {'enabled': v:true}}}}
" \ })
"endif
" Set *.jinja to be jinja2
au BufRead,BufNewFile *.jinja set filetype=jinja2
"" Shell
let g:ale_sh_shellcheck_change_directory=0
let g:ale_sh_shellcheck_options='--external-sources'
" API Blueprint
" Fix ctrl-b to be back still
autocmd FileType apiblueprint nnoremap <C-b> <S-Up>
" Gherkin
au FileType cucumber setlocal textwidth=88
" Markdown (vim-polygot)
" TODO(ppg): re-flowing bullets doesn't work with auto-insert bullets;
" I keep auto-insert since auto-wrap works while typing, although when
" wrapped bullet insertion no longer works. Some issues:
" https://github.com/preservim/vim-markdown/issues/232 - Rewrapping a bullet point inserts new bullet points
" https://github.com/preservim/vim-markdown/issues/390 - gq wrapping is still broken
" This appears to have no effect for some reason to fix things?
" au FileType markdown setlocal comments=fb:*,fb:+,fb:-,n:> indentexpr=
" Is there no solution that allows:
"
" 1. auto-insert new list items when hitting ENTER or O at the same indentation
" 2. auto-wrap on text entry; including when you hit ENTER for 1
" 3. allow reformatting of bullets that are too long without inserting new
" bullets.
let g:vim_markdown_frontmatter = 1
" let g:vim_markdown_folding_disabled = 0
let g:vim_markdown_auto_insert_bullets = 1
let g:vim_markdown_new_list_item_indent = 2
au FileType markdown setlocal wrap linebreak textwidth=72 nolist autoindent
" Define the markdownlint-cli2 handler for ALE until they release their
" support
function! ALEMarkdownLintCli2Handler(buffer, lines) abort
" Logic:
" Group 1: Line number (digits after the first colon)
" Group 2: Optional column (digits after a second colon)
" Group 3: Rule ID
" Group 4: Description
let l:pattern = '\v^[^:]+:(\d+)%(:(\d+))?%(\s+error)?\s+(MD\d{3}\S*)\s+(.*)$'
let l:output = []
for l:line in a:lines
let l:match = matchlist(l:line, l:pattern)
if !empty(l:match)
" If match[2] is empty, the digits found were just the line number.
" If match[2] is NOT empty, then match[1] is line and match[2] is col.
let l:line_num = l:match[1] + 0
let l:col_num = l:match[2] != '' ? l:match[2] + 0 : 1
call add(l:output, {
\ 'lnum': l:line_num,
\ 'col': l:col_num,
\ 'text': l:match[3] . ': ' . l:match[4],
\ 'type': 'W',
\})
endif
endfor
return l:output
endfunction
call ale#linter#Define('markdown', {
\ 'name': 'markdownlint-cli2',
\ 'executable': 'markdownlint-cli2',
\ 'command': 'markdownlint-cli2 %t 2>&1',
\ 'callback': 'ALEMarkdownLintCli2Handler',
\})
" Override filetypes
au BufRead,BufNewFile Dockerfile.* set filetype=dockerfile
au BufRead,BufNewFile .eslintrc set filetype=json
" Override *.ino to be Arduino files
au BufRead,BufNewFile *.ino set filetype=cpp
" Nginx
au BufRead,BufNewFile */nginx/conf.d/* set ft=nginx
" Define common tabularizations
if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
nmap <Leader>a, :Tabularize /,\zs<CR>
vmap <Leader>a, :Tabularize /,\zs<CR>
endif
" TODO Probably put these in after insert too like cucumber?
" Tabularize cucumber after insert
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
" vim-spec
map <Leader>rt :call RunCurrentSpecFile()<CR>
map <Leader>rs :call RunNearestSpec()<CR>
map <Leader>rl :call RunLastSpec()<CR>
map <Leader>ra :call RunAllSpecs()<CR>