-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc.plugins
More file actions
392 lines (348 loc) · 13.1 KB
/
.vimrc.plugins
File metadata and controls
392 lines (348 loc) · 13.1 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
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
scriptencoding utf-8
" run plugged
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/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')
"""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins that change or add functionality
"""""""""""""""""""""""""""""""""""""""""""""""""""""
"fancypants status line
Plug 'itchyny/lightline.vim'
let g:lightline = {
\ 'colorscheme': 'one',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'fugitive', 'filename', 'modified', 'readonly' ] ],
\ 'right': [ [ 'gutentags'],
\ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype' ] ]
\ },
\ 'component': {
\ 'readonly': "%{&readonly?'🔒':''}",
\ },
\ 'component_function': {
\ 'fugitive': 'LightlineFugitive',
\ 'filename': 'LightlineFilename',
\ 'gutentags': 'gutentags#statusline'
\ },
\ }
function! IsQFLLFocused()
silent! exec 'redir @a | ls | redir END'
if match(@a,'%a- "\[Location List\]"') >= 0
return 1
elseif match(@a,'%a- "\[Quickfix List\]"') >= 0
return 2
else
return 0
endif
endfunction
function! LightlineFugitive()
if &filetype !~? 'vimfiler' && exists('*fugitive#head')
return fugitive#head()
endif
return ''
endfunction
function! LightlineFilename()
let l:is_special_focused = IsQFLLFocused()
if l:is_special_focused == 1
return '[Local/Location List]'
elseif l:is_special_focused == 2
return '[Global/QuickFix]'
endif
let l:short_filename = expand('%:t') !=# '' ? expand('%:t') : '[No Name]'
let l:med_filename = expand('%:t') !=# '' ? fnamemodify(expand('%:p'), ':~:.') : '[No Name]'
let l:full_filename = expand('%:t') !=# '' ? fnamemodify(expand('%:p'), ':~:.') : '[No Name]'
let l:max_len = 120
let l:full_len = len(l:full_filename)
let l:med_len = len(l:med_filename)
let l:use_short = l:full_len > l:max_len && l:med_len > l:max_len
let l:use_med = l:full_len > l:max_len && l:med_len <= l:max_len
return l:use_short ? l:short_filename : l:use_med ? l:med_filename : l:full_filename
endfunction
"visual undo tree. nice for when you need to go back to a branch
Plug 'sjl/gundo.vim'
if has('python3')
let g:gundo_prefer_python3 = 1
endif
nnoremap <silent> <leader>Wg :GundoToggle<CR>
"provides hg/git change status in the left gutter
Plug 'mhinz/vim-signify'
"fzf for finding files, buffers
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
" disable the preview window
let g:fzf_preview_window =''
let $FZF_DEFAULT_COMMAND = 'rg --files --hidden'
nnoremap <silent> <C-p> :Files<CR>
nnoremap <silent> <leader>fb :Buffers<CR>
nnoremap <silent> <leader>ff :Files<CR>
nnoremap <silent> <leader>fi :Rg<CR>
"display marks
Plug 'kshenoy/vim-signature'
"Alternative to netrw, which is slow and buggy
Plug 'jeetsukumaran/vim-filebeagle'
let g:filebeagle_show_hidden=1
"Git wrapper for doing git things on files in vim
Plug 'tpope/vim-fugitive'
Plug 'tommcdo/vim-fugitive-blame-ext' " Show commit message in fugitive blame window
command! Greview :Git! diff --staged
"leader-b will toggle git blame
nmap <expr> <leader>b &filetype ==# 'fugitiveblame' ? "gq" : ":Git blame\r"
augroup fugitivecleanup
"Cleanup fugitive buffers automatically
autocmd!
autocmd BufReadPost fugitive://* set bufhidden=delete
augroup END
"Show the diff when editing a git commit.
Plug 'rhysd/committia.vim'
"Expands motion keys for faster jumps
Plug 'easymotion/vim-easymotion'
let g:EasyMotion_do_mapping = 0 " Disable default mappings
" Jump to anywhere you want with minimal keystrokes, with just one key binding.
" `s{char}{char}{label}`
" Need one more keystroke, but on average, it may be more comfortable.
nmap s <Plug>(easymotion-overwin-f2)
" overwrite the default S, which is a synonym of cc, for when using S to seek backwards
nmap S <Plug>(easymotion-overwin-f2)
" Turn on case-insensitive feature
let g:EasyMotion_smartcase = 1
" JK motions: Line motions
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
"Command line, mostly for :Rename and :Move
Plug 'tpope/vim-eunuch'
"replace {motion} with a register. Faster than typing '"_c[motion]^r"'
Plug 'vim-scripts/ReplaceWithRegister'
"""""""""""""""""""""""""""""""""""""""""""""""""""""
" linting
"""""""""""""""""""""""""""""""""""""""""""""""""""""
Plug 'yegappan/lsp'
let g:lsp_use_native_client = 1
let lspOptions = #{
\ aleSupport: v:true,
\ completionTextEdit: v:true,
\ noNewlineInCompletion: v:true,
\ outlineWinSize: 70,
\ showDiagWithSign: v:false,
\ useQuickfixForLocations: v:true,
\ }
" autocmd VimEnter * call LspOptionsSet(lspOptions)
autocmd User LspSetup call LspOptionsSet(lspOptions)
let g:mylsp_path = !empty($VIRTUAL_ENV) ? $VIRTUAL_ENV . '/bin/pylsp' : 'pylsp'
if !empty($IDF_PATH)
" If we are in an ESP environment, use the esp-clangd implementation to avoid unknown triples
" install with `idf_tools.py install esp-clang`
let clanglsp = #{name: 'esp-clangd',
\ filetype: ['c', 'cpp'],
\ path: '/home/adam/.espressif/tools/esp-clang/16.0.1-fe4f10a809/esp-clang/bin/clangd',
\ args: [
\ '--header-insertion=never',
\ '--background-index',
\ '--query-driver=**']}
else
let clanglsp = #{name: 'clang',
\ filetype: ['c', 'cpp'],
\ path: 'clangd',
\ args: [
\ '--header-insertion=never',
\ '--background-index',
\ '--query-driver=/usr/bin/arm-none-eabi-*,/usr/bin/gcc-*']}
endif
let lspServers = [
\ #{name: 'gopls', filetype: ['go', 'gomod'], path: 'gopls', args: ['serve']},
\ #{name: 'pylsp', filetype: ['py', 'python'], path: g:mylsp_path, args: []},
\ clanglsp,
\ #{name: 'rustlang',
\ filetype: ['rust'],
\ path: 'rust-analyzer',
\ args: [],
\ syncInit: v:true,
\ initializationOptions: #{
\ check: #{ command: 'clippy' },
\ inlayHints: #{
\ typeHints: #{ enable: v:true },
\ parameterHints: #{ enable: v:true }},
\ }
\ }]
autocmd User LspSetup call LspAddServer(lspServers)
"Enable auto selection of the fist autocomplete item
"augroup LspSetup
" au!
autocmd User LspAttached set completeopt-=noselect
"augroup END
"Mappings for most-used functions
nnoremap <leader>d :LspHover<CR>
nnoremap <leader>gd :LspGotoDefinition<CR>
nnoremap <leader>gr :LspPeekReferences<CR>
nnoremap <leader>gs :LspDocumentSymbol<CR>
nnoremap <leader>pd :LspPeekDefinition<CR>
" Linters for everything
Plug 'dense-analysis/ale'
"Disable ALE's LSP in favour of standalone LSP plugin - note all LSP linters will be auto-ignored
let g:ale_disable_lsp = 1
"Show linting errors with highlights
let g:ale_set_signs = 1
let g:ale_set_highlights = 1
let g:ale_virtualtext_cursor = 0
highlight ALEError ctermbg=none cterm=underline
"Define when to lint
let g:ale_lint_on_save = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_text_change = 'never'
let g:ale_linters_explicit = 1
let g:ale_linters = {
\ 'c': ['clangd', 'clangtidy'],
\ 'go': ['gofmt', 'gopls', 'govet', 'gobuild'],
\ 'markdown': ['mdl', 'languagetool'],
\ 'python': ['mypy'],
\ }
let g:ale_linters_ignore = {}
let g:ale_c_clangd_options = "-Wno-unused-command-line-argument"
let g:ale_c_clangtidy_extra_options = "-Wno-unused-command-line-argument"
let g:ale_fixers = {
\ '*': ['trim_whitespace'],
\ 'c': ['trim_whitespace'],
\ 'python': ['isort', 'yapf', 'remove_trailing_lines', 'trim_whitespace'],
\ 'go': ['gopls', 'goimports', 'gofmt', 'gotype', 'govet'],
\ }
"Don't warn about trailing whitespace, as it is auto-fixed by '*' above
let g:ale_warn_about_trailing_whitespace = 0
"Show info, warnings, and errors; Write which linter produced the message
let g:ale_lsp_show_message_severity = 'information'
let g:ale_echo_msg_format = '[%linter%] [%severity%:%code%] %s'
"Specify Containerfiles as Dockerfiles
let g:ale_linter_aliases = {"Containerfile": "dockerfile"}
"Mapping to run fixers on file
nnoremap <leader>L :ALEFix<CR>
" Clang Format
Plug 'rhysd/vim-clang-format'
let g:clang_format#code_style="chromium"
let g:clang_format#command="clang-format"
let g:clang_format#style_options = { "ColumnLimit" : 120 }
let g:clang_format#detect_style_file=1
" map to <Leader>cf in C++ code
autocmd FileType c,cpp,objc nnoremap <buffer><Leader>cf :<C-u>ClangFormat<CR>
autocmd FileType c,cpp,objc vnoremap <buffer><Leader>cf :ClangFormat<CR>
" Ctags auto update
Plug 'ludovicchabant/vim-gutentags'
if executable('rg')
let g:gutentags_file_list_command = 'rg --files'
endif
"Adhere to linux coding style guidelines
Plug 'vivien/vim-linux-coding-style', {'for': 'c'}
let g:linuxsty_patterns = []
"""""""""""""""""""""""""""""""""""""""""""""""""""""
" Extra language support, such as syntax highlighting, repl interaction
"""""""""""""""""""""""""""""""""""""""""""""""""""""
" Rust
Plug 'rust-lang/rust.vim', {'for': 'rust'}
let g:rustfmt_autosave = 1
" :Graphviz! png
Plug 'liuchengxu/graphviz.vim', {'for': 'dot'}
"Linux kernel/Buildroot Kconfig syntax
Plug 'chrisbra/vim-kconfig', {'for': 'kconfig'}
"Syntax, indent, ftplugin for a bunch of languages
Plug 'sheerun/vim-polyglot'
" Extra highlighting for c/c++
Plug 'octol/vim-cpp-enhanced-highlight', {'for': ['c', 'cpp']}
"Support for viewing markdown rendering
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
"Don't automatically close the preview window when I look at another buffer
let g:mkdp_auto_close = 0
"Define our own function for launching the background browser
function! g:Open_browser(url)
silent exe 'silent !firefox -P default -url ' . a:url . ' &'
endfunction
let g:mkdp_browserfunc = 'g:Open_browser'
nmap <leader>m <Plug>MarkdownPreviewToggle
"Syntax highlighting for plantuml, also assigns makeprg
" Depends on having a 'plantuml' in the path, could be a script:
" #!/bin/bash
" java -jar $HOME/lib/java/plantuml.jar -tsvg $@
Plug 'aklt/plantuml-syntax', {'for': 'plantuml'}
" Open links in browser, used for plantuml viewer
Plug 'tyru/open-browser.vim', {'for': 'plantuml'}
" Preview plugin for plantuml
Plug 'weirongxu/plantuml-previewer.vim', {'for': 'plantuml'}
au FileType plantuml let g:plantuml_previewer#plantuml_jar_path = '/home/adam/.bin/plantuml.jar'
"""""""""""""""""""""""""""""""""""""""""""""""""""""
" color schemes
"""""""""""""""""""""""""""""""""""""""""""""""""""""
Plug 'pacokwon/onedarkhc.vim'
Plug 'rakr/vim-one'
call plug#end()
function! SetupEnvironment()
" Alternative to this approach is running with exrc, though this has security implications.
" This approach is the approach suggested by Braam, and it turns out it is nice to see all of
" the project settings in one file.
let l:path = expand('%:p')
" Does path contain the kernel_modules
if l:path =~# 'acadia/kernel_modules'
let g:linuxsty_patterns = ['/home/adam/projects/idexx/acadia/kernel_modules/']
" use `bear make` for autocompletion and syntax checks
setlocal listchars=tab:\»\ ,trail:·,extends:…
setlocal noexpandtab
setlocal tabstop=8
setlocal shiftwidth=8
setlocal textwidth=80
setlocal colorcolumn=81
elseif l:path =~# 'reflex_workspace'
setlocal expandtab
setlocal tabstop=4
setlocal shiftwidth=4
if &filetype ==? 'gitcommit'
setlocal textwidth=80
setlocal colorcolumn=81
else
setlocal textwidth=100
setlocal colorcolumn=101
endif
elseif l:path =~# 'goe-rts-driver'
let g:linuxsty_patterns = ['/home/adam/go-e/Repos/goe-rts-driver/']
" use `bear make` for autocompletion and syntax checks
setlocal listchars=tab:\»\ ,trail:·,extends:…
setlocal noexpandtab
setlocal tabstop=8
setlocal shiftwidth=8
setlocal textwidth=80
setlocal colorcolumn=81
elseif l:path =~# 'rts-firmware'
if &filetype ==? 'c' || &filetype ==? 'cpp'
setlocal noexpandtab
setlocal tabstop=8
setlocal shiftwidth=8
elseif &filetype ==? 'python'
setlocal expandtab
setlocal tabstop=4
setlocal shiftwidth=4
endif
elseif l:path =~# 'SmartThermostat'
if &filetype ==? 'c' || &filetype ==? 'cpp'
setlocal noexpandtab
setlocal tabstop=4
setlocal shiftwidth=4
elseif &filetype ==? 'python'
setlocal expandtab
setlocal tabstop=4
setlocal shiftwidth=4
endif
elseif l:path =~# 'acadia/applications'
let g:gutentags_ctags_exclude = ['node_modules']
if &filetype ==? 'python'
setlocal textwidth=100
setlocal colorcolumn=101
endif
let g:python_auto_pipenv = 0
else
let g:linuxsty_patterns = []
endif
endfunction
augroup envswitch
" Clean up envswitch group
autocmd!
autocmd VimEnter,WinEnter,BufWinEnter,BufReadPost,BufNewFile * call SetupEnvironment()
augroup END