/
.vimrc
580 lines (476 loc) · 20.1 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
" Config file for vim
" enable all vim features
set nocompatible
" enable filetype detection as well as type-specific plugin/indentation
filetype plugin indent on
" text options
syntax on " syntax highlight
set wrap " wrap long lines
"set textwidth=100 " text width
" indent options
"set tabstop=4 " Tabs are 4 characters
"set shiftwidth=4 " (Auto)indent uses 4 characters
set tabstop=2 " Tabs are 2 characters
set shiftwidth=2 " (Auto)indent uses 2 characters
set expandtab " spaces instead of tabs
set smarttab " smart tab
set autoindent " guess indentation
set smartindent " smart autoindenting when starting a new line
" searching
set hlsearch " highlight the search terms
set incsearch " jump to the matches while typing
set ignorecase " ignore case for searches
set smartcase " case sensitive when using capitals in search phrase
" commandline completion
set wildmenu " command-line completion
set wildmode=list:longest,list:full " set mode of completion
set wildchar=<Tab> " expand the command line using tab
set wildignore=*.o,*.e,*~ " ignore these extensions for completion
" completion menu
set completeopt=menuone,longest,popup " always show the menu, insert longest match, use popup window for extra info
"set completepopup=border:off " remove the border from the completion popup window
" turn on omnicomplete. we set this based on ale plugin later
"set omnifunc=syntaxcomplete#Complete " vim default
" enhancements over vi
set showcmd " show (partial) command in status line
set showmatch " show matching brackets
set autowrite " automatically save before commands like :next and :make
set hidden " hide buffers when they are abandoned
set mouse=a " enable mouse usage (all modes)
" config for directory explorer (simulating nerdtree)
let g:netrw_banner = 0 "do not display info on the top of window
let g:netrw_liststyle = 3 " tree view
let g:netrw_winsize = 25 " width of netrw window
" other options
set ttyfast " speed up scrolling in Vim
set autochdir " change directory for each file opened
set splitbelow " show preview window at the bottom
" directly use system clipboard for yank/paste operations
"set clipboard=unnamedplus
" plugins ---------------------------------------------------------------------
" specify a directory for plugins, for installaion via vim-plug
" avoid using standard Vim directory names like 'plugin'
" for the dotfiles repo, the plugins are present as git submodules
call plug#begin('~/.vim/plugged')
" appearance
Plug 'itchyny/lightline.vim'
Plug 'edkolev/tmuxline.vim'
Plug 'maximbaz/lightline-ale'
" essentials
"Plug 'dense-analysis/ale' " enable after the fork branch is merged upstream
Plug 'anupdhml/ale', { 'branch': 'tremor_integration' }
Plug 'scrooloose/nerdcommenter'
Plug 'ajh17/VimCompletesMe'
Plug 'liuchengxu/vim-clap', { 'do': ':Clap install-binary' }
Plug 'liuchengxu/vista.vim'
Plug 'ludovicchabant/vim-gutentags'
" git
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-rhubarb'
" utilities
Plug 'tpope/vim-obsession'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-endwise'
Plug 'Valloric/ListToggle'
" language support
Plug 'rodjek/vim-puppet', { 'for': 'puppet' }
Plug 'hashivim/vim-terraform', { 'for': 'terraform' }
Plug 'fatih/vim-go', { 'for': 'go', 'do': ':GoUpdateBinaries' } " TODO configure options here
Plug 'rust-lang/rust.vim', { 'for': 'rust' }
Plug 'wayfair-tremor/tremor-vim', { 'for': 'tremor,trickle' }
Plug 'junegunn/vader.vim', { 'for': 'vader' }
Plug 'luochen1990/rainbow', { 'for': 'clojure,html,xml' }
Plug 'eraserhd/parinfer-rust', { 'for': 'clojure', 'do': 'cargo build --release' }
Plug 'guns/vim-sexp', { 'for': 'clojure' }
Plug 'tpope/vim-sexp-mappings-for-regular-people', { 'for': 'clojure' }
Plug 'liquidz/vim-iced', { 'for': 'clojure' }
Plug 'bfontaine/zprint.vim', { 'for': 'clojure' }
Plug 'guns/vim-clojure-static', { 'for': 'clojure' }
Plug 'cespare/vim-toml', { 'for': 'toml' }
" initialize plugin system
call plug#end()
" lightline -------------------------------------------------------------------
" for generating tmux status bar config from vim (aligning tmux appearance with vim lightline)
let g:tmuxline_powerline_separators = 0
let g:tmuxline_theme = 'powerline'
let g:tmuxline_preset = 'minimal'
" lightline configuration
let g:lightline = {}
" aligned with tmuxline theme
let g:lightline.colorscheme = 'powerline'
function! NearestMethodOrFunction() abort
return get(b:, 'vista_nearest_method_or_function', '')
endfunction
" for showing following extra info on the statusline:
" * git branch: depends on vim-fugitive
" * nearest method: gdepends on vista.vim
let g:lightline.component_function = {
\ 'fugitive': 'fugitive#head',
\ 'method': 'NearestMethodOrFunction',
\ }
" for showing linter errrors/warnings. depends on lightline-ale
let g:lightline.component_expand = {
\ 'linter_checking': 'lightline#ale#checking',
\ 'linter_warnings': 'lightline#ale#warnings',
\ 'linter_errors': 'lightline#ale#errors',
\ 'linter_ok': 'lightline#ale#ok',
\ }
let g:lightline.component_type = {
\ 'linter_checking': 'left',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error',
\ 'linter_ok': 'left',
\ }
let g:lightline#ale#indicator_checking = ''
let g:lightline#ale#indicator_warnings = '▲'
let g:lightline#ale#indicator_errors = '✗'
let g:lightline#ale#indicator_ok = '✓'
" configure lightline components
let g:lightline.active = {
\ 'left': [ ['mode', 'paste'],
\ ['fugitive', 'readonly', 'filename', 'modified', 'method'] ],
\ 'right': [ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype' ],
\ ['linter_checking', 'linter_errors', 'linter_warnings', 'linter_ok' ] ]
\ }
" these settings work well with statuslines like lightline
set laststatus=2 " always display the statusline in all windows
set noshowmode " hide the default mode text (e.g. -- INSERT -- below the statusline)
" instantly leave insert mode when pressing <Esc>
" useful to have with statuslines like lightline
set ttimeoutlen=10
augroup FastEscape
autocmd!
au InsertEnter * set timeoutlen=0
au InsertLeave * set timeoutlen=1000
augroup END
" ale -------------------------------------------------------------------------
" TODO play with completion, go to definiton, hovering etc
" https://github.com/w0rp/ale#2-usage
" turn on omnicomplete based on ale
set omnifunc=ale#completion#OmniFunc
" enable ale completion (as you type), where available
"let g:ale_completion_enabled = 1
" completion menu options in case ale completion gives issues
" TODO remove
"set completeopt=menu,menuone,preview,noselect,noinsert
" show hover information on mouse over (vim mouse support should be turned on)
" xterm2 makes hover work with tmux as well
let g:ale_set_balloons = 1
set ttymouse=xterm2
" only run linters named in ale_linters settings
let g:ale_linters_explicit = 1
" when to run linting/fixing
"let g:ale_fix_on_save = 1
"let g:ale_lint_on_text_changed = 'always'
"let g:ale_lint_on_enter = 1
"let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_enter = 0
let g:ale_lint_on_insert_leave = 0
" ale indicators (aligned with indicators used in lightline-ale)
" 2 chars to cover the full sign width
let g:ale_sign_warning = '▲▲'
let g:ale_sign_error = '✗✗'
" appearance settings
let g:ale_set_signs = 0 " no gutter ever. we rely on highlights/statusline
"let g:ale_sign_column_always = 1 " always show the gutter
"let g:ale_open_list = 1 " show window for error list
"let g:ale_list_window_size = 10 " height of the window for error list
"let g:ale_close_preview_on_insert = 1 " close preview window automatically
" active linters
let g:ale_linters = {
\ 'clojure': ['clj-kondo'],
\ 'css': ['stylelint'],
\ 'puppet': ['puppetlint'],
\ 'rust': ['analyzer'],
\ 'tremor': ['tremor-language-server'],
\ 'trickle': ['tremor-language-server'],
\}
" active fixers
let g:ale_fixers = {
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
\ 'css': ['stylelint'],
\ 'go': ['gofmt'],
\ 'puppet': ['puppetlint'],
\ 'rust': ['rustfmt'],
\}
" ale rust settings, applicable when using rls as the ale linter
" for avaialble params to rust language server, see: https://github.com/rust-lang/rls#configuration
"let g:ale_rust_rls_config = {
"\ 'rust': {
"\ 'clippy_preference': 'on',
"\ }
"\}
" ale rust settings, applicable when using cargo as the ale linter
"let g:ale_rust_cargo_check_tests = 1 " lint rust tests too
"let g:ale_rust_cargo_check_examples = 1 " list rust examples too
"let g:ale_rust_cargo_use_clippy = executable('cargo-clippy') " use cargo clippy for lints if present
"let g:ale_rust_cargo_clippy_options = '' " options for cargo clippy
" other plugin settings -------------------------------------------------------
" for rust files, run rustfmt on buffer save
" since ale can't fix on :wq, we choose rust.vim's functionality here:
" https://github.com/w0rp/ale/issues/2014#issuecomment-493559554
let g:rustfmt_autosave = 1
" Align line-wise comment delimiters flush left instead of following code indentation
let g:NERDDefaultAlign = 'left'
" list toggle
let g:lt_height = 10
" enable fenced code block syntax highlighting in markdown files for these languages
let g:markdown_fenced_languages = ['tremor', 'trickle']
" syntax highlighting for certain clojurescript elements
"let g:clojure_syntax_keywords = {
" \ 'clojureFunc': [
" \ ".indexOf", ".lastIndexOf",
" \ ".render", ".createElement", ".getElementById"
" \ ]
" \ }
" override default vista executive (ctags) for these filetypes
" useful when other executives (eg: lsp servers) give better results than ctags
"let g:vista_executive_for = {
" \ 'rust': 'ale',
" \ }
" for vim-clap (with rg). via `:h clap-grep-options`
let g:clap_provider_grep_opts = '--with-filename --no-heading --vimgrep --smart-case --hidden'
" does not work as expected so disabled
"let g:clap_provider_grep_opts = '--with-filename --no-heading --vimgrep --smart-case --hidden --glob "!.git/"'
" for vim-iced (clojure support)
let g:iced_enable_default_key_mappings = v:true
"let g:iced_formatter = 'zprint'
" enables use of vim-iced formatting function
let g:sexp_mappings = {'sexp_indent': '', 'sexp_indent_top': ''}
" for parinfer-rust (clojure/lisp support)
" enables typing of brackets in insert mode (without annoying errors)
let g:sexp_enable_insert_mode_mappings = 0
" enable rainbow parentheses
" more options at: https://github.com/luochen1990/rainbow#configure
let g:rainbow_active = 1
" choosing colors appropritate for light colorscheme
let g:rainbow_conf = {
\ 'ctermfgs': ['darkblue', 'darkyellow', 'darkcyan', 'darkmagenta'],
\}
" theme -----------------------------------------------------------------------
"if !has('gui_running')
" set t_Co=256
"endif
" this needs to be set before intializing colorschemes
set background=light
if $TERM == "rxvt-unicode-256color" && !has('gui_running')
" only on terminal vim
colorscheme default_improved
" for vim-clap
"
" TODO show icons for urxvt
"let g:clap_enable_icon = 1
"let g:clap_provider_grep_enable_icon = 1
"
" TODO support spinner symbol rendering in urxvt. can then use it in the prompt
"let g:clap_prompt_format = '%spinner%%forerunner_status%%provider_id%:' "default
let g:clap_prompt_format = '%forerunner_status%%provider_id%:'
"
" colors for fuzzy matches on places like `:Clap files`
let g:clap_fuzzy_match_hl_groups = [
\ [24, 'darkblue'],
\ [4, 'blue'],
\]
" cursor char on clap prompt
let g:clap_popup_cursor_shape = '|'
" for vista.vim
" TODO show icons for urxvt
let g:vista#renderer#enable_icon = 0
else
"set termguicolors
"set background=light
"colorscheme solarized8
colorscheme flattened_light
" italicize comments, except on terminals that don't support it
if $TERM == "linux"
highlight Comment cterm=none ctermfg=darkgrey
else
highlight Comment cterm=italic
endif
" for vim-clap
" icons work well in gvim and xfce4-terminal (as long as nerd fonts are
" installed), so enable it too
let g:clap_enable_icon = 1
let g:clap_provider_grep_enable_icon = 1
let g:clap_theme = 'solarized_light'
endif
" command maps -----------------------------------------------------------------
command S Obsession
" connnect to shadow-clsj repl easily, for clojurescript projects
" takes the build-id as argument. eg: `:IcedShadow app`
command -nargs=1 IcedShadow IcedStartCljsRepl shadow-cljs <args>
" key bindings -----------------------------------------------------------------
" fast switching between buffers with shift-tab. The current buffer will be
" saved before switching to the next one.
noremap <silent> <S-tab> :if &modifiable && !&readonly && &modified
\ <CR> :write<CR> :endif<CR>:bprevious<CR>
inoremap <silent> <S-tab> <C-C>:if &modifiable && !&readonly && &modified
\ <CR> :write<CR> :endif<CR>:bprevious<CR>
" ctrl-A, ctrl-E for beginning and end of line, similar to emacs-style commandline defaults
" map! makes the mapping work in insert and commandline modes too
map <C-A> <Home>
map <C-E> <End>
map! <C-A> <Home>
map! <C-E> <End>
" after shifting a visual block, select it again
vnoremap < <gv
vnoremap > >gv
" add blank line on enter
nmap <Return> o<Esc>
" copy to system clipboard with cy (follow with a motion movement)
nnoremap cy "+y
vnoremap cy "+y
" paste from system clipboard with cp
nnoremap cp "+p<cr>
vnoremap cp "+p<cr>
" run previous command on the first window (and first pane) of the current tmux session
" works well only if history is in-sync across all panes
"nmap \r :!tmux send-keys -t "$(tmux display-message -p '\#S'):1.1" C-p C-j <CR><CR>
" auto-closing pairs in insert mode
"inoremap " ""<left>
"inoremap ' ''<left>
"inoremap ( ()<left>
"inoremap [ []<left>
" these are disabled because they can be annoying with auto-indents
"inoremap { {}<left>
"inoremap {<CR> {<CR>}<ESC>O
"inoremap {;<CR> {<CR>};<ESC>O
" key bindings (function keys) ------------------------------------------------
" F1 - open file picker
map <silent> <F1> :Clap files --hidden<CR>
map <silent> ,<F1> :Clap!! files --hidden<CR>
" F2 - open grep picker
map <silent> <F2> :Clap grep<CR>
map <silent> ,<F2> :Clap!! grep<CR>
" F3 - open tags picker
map <silent> <F3> :Clap tags<CR>
map <silent> ,<F3> :Clap proj_tags<CR>
" F4 - toggle file explorer
map <silent> <F4> :Lexplore<CR>
map <silent> ,<F4> :Clap filer<CR>
" F5 - toggle tags explorer (via vim-vista)
map <silent> <F5> :Vista!!<CR>
map <silent> ,<F5> :Vista ale<CR>
" F6 - toggle linenumbers/statusline
map <silent> <F6> :set nonumber!<CR>
map <silent> ,<F6> :if &laststatus == 1<bar>
\set laststatus=2<bar>
\set noshowmode<bar>
\echo<bar>
\else<bar>
\set laststatus=1<bar>
\set showmode<bar>
\endif<CR>
" F7 - toggle cursor line/column
map <silent> <F7> :set cursorline!<CR>
map <silent> ,<F7> :set cursorcolumn!<CR>
" F8 - toggle comment (depends on nerdcommenter)
map <silent> <F8> ,c<Space>
imap <silent> <F8> <Esc>,c<Space>
map <silent> ,<F8> ,cs
imap <silent> ,<F8> <Esc>,cs
" F9 - open git diff picker
map <silent> <F9> :Clap git_diff_files<CR>
map <silent> ,<F9> :Clap bcommits<CR>
" F10 - open buffers/windows picker
map <silent> <F10> :Clap buffers<CR>
map <silent> ,<F0> :Clap windows<CR>
" F11 - open quickfix list (toggle depends on listtoggle)
map <silent> <F11> :Clap quickfix<CR>
let g:lt_quickfix_list_toggle_map = ',<F11>'
" F12 - open location list (toggle depends on listtoggle)
map <silent> <F12> :Clap loclist<CR>
let g:lt_location_list_toggle_map = ',<F12>'
" key bindings (leader based) -------------------------------------------------
" With a map leader it's possible to do extra key combinations
let mapleader = ","
let g:mapleader = ","
" toggle paste mode
set pastetoggle=<leader>P
" for ale
nmap <silent> <leader>j <Plug>(ale_next_wrap)
nmap <silent> <leader>k <Plug>(ale_previous_wrap)
nmap <silent> <leader>/ <Plug>(ale_hover)
nmap <silent> <leader>? <Plug>(ale_detail)
nmap <silent> <leader>] <Plug>(ale_go_to_definition)
nmap <silent> <leader># <Plug>(ale_find_references)
" extra mapping for getting documentation, matching plugins like
" vim-iced (or vim native man functionality)
nmap <silent> K <Plug>(ale_hover)
" fzy integration (when opening files from vim)
function! FzyCommand(choice_command, vim_command)
try
let output = system(a:choice_command . " | fzy ")
catch /Vim:Interrupt/
" Swallow errors from ^C, allow redraw! below
endtry
redraw!
if v:shell_error == 0 && !empty(output)
exec a:vim_command . ' ' . output
endif
endfunction
nnoremap <leader>fe :call FzyCommand("fdfind --type file --follow --hidden --exclude .git . $(git rev-parse --show-toplevel 2>/dev/null)", ":e")<cr>
"nnoremap <leader>fe :call FzyCommand("fdfind --type file --follow --hidden --exclude .git", ":e")<cr>
nnoremap <leader>fg :call FzyCommand("git ls-files $(git rev-parse --show-toplevel)", ":e")<cr>
" for running git commands on current file
" TODO make it work as a :Git command. or as :Gblame...
fun! GitCommand(command)
silent! !clear
exec "!git " . a:command . " %"
endfun
map <leader>gb :call GitCommand("blame") <CR><CR>
map <leader>gd :call GitCommand("diff") <CR><CR>
map <leader>gl :call GitCommand("log -p") <CR><CR>
" for quickly retrieving the syntax highlight group active under the cursor
function! SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunction
function! SynGroup()
let l:s = synID(line('.'), col('.'), 1)
echo synIDattr(l:s, 'name') . ' -> ' . synIDattr(synIDtrans(l:s), 'name')
endfunction
map <leader>sg :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" autocmd ----------------------------------------------------------------------
" needed to show the nearest function in statusline automatically (via vista.vim)
autocmd VimEnter * call vista#RunForNearestMethodOrFunction()
" have vim jump to the last position when reopening a file
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" override <CR> mapping defined earlier in the file, for quickfix/loclist
" window (since <CR> is used to jump to the error under the cursor there)
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
" remove trailing whitespaces (for certain filetypes) automatically on file save
autocmd FileType
\ awk,c,calendar,changelog,clojure,coffee,conf,config,cpp,css,desktop,dircolors,dockerfile,eruby,erlang,git,go,grub,haskell,html,java,javascript,jproperties,json,lua,make,man,markdown,perl,php,puppet,python,readline,ruby,scala,sh,sql,sshconfig,sudoers,systemd,terraform,tremor,trickle,tmux,vader,vim,xdefaults,xml,yaml
\ autocmd BufWritePre <buffer> :%s/\s\+$//e
" override iskeword set from vim-puppet/ftplugin/puppet.vim, to ingnore ':'
" (so that we can do things like word matches on module variable's word parts
autocmd FileType puppet setl iskeyword=-,@,48-57,_,192-255
augroup filetype_clojure
autocmd!
" start repl connection automatically for clojure files. needed for vim-iced
function! s:iced_auto_connect() abort
if expand('%:e') ==# 'cljs'
" assumes that 'app' is the id used for cljs projects
" `shadow-cljs watch` must already be running for this to work
silent IcedStartCljsRepl shadow-cljs app
else
silent IcedConnect
endif
endfunction
" ++nested fixes initial lightline rendering issues
" https://github.com/itchyny/lightline.vim/issues/406#issuecomment-570141322"
autocmd FileType clojure
\ autocmd VimEnter * ++nested call s:iced_auto_connect()
" run formatter on clojure file writes (via vim-iced)
" TODO fix this. not working reliably. for now, we rely on formatting via zprint.vim
"autocmd FileType clojure
" \ autocmd BufWritePre <buffer> :IcedFormat
augroup END