-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
577 lines (478 loc) · 16.6 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
syntax on
set number
set relativenumber
"indent options
set ai
"search incrementally and highlighting
set incsearch
set hlsearch
"show matching brackets
set showmatch
"tab completion
set wildmode=longest:full
set wildmenu
"set semi-colon to colon
nore ; :
nore : ;
" open up the full color range
" set t_Co=256
""" Use truecolours
set termguicolors
"dark background color
set background=dark
"shift >>/<< width
set shiftwidth=2
set tabstop=2
"Use Enter/Shift-Enter to introduce new lines above/below w/o leaving normal mode
nnoremap <Enter> o<ESC>
call plug#begin('~/.vim/bundle')
""" Language specific syntax,completion etc
Plug 'derekwyatt/vim-scala'
Plug 'wlangstroth/vim-racket'
Plug 'jakwings/vim-pony'
" Requires jedi(pip)
Plug 'davidhalter/jedi-vim'
" syntax based code folding for python
Plug 'tmhedberg/SimpylFold'
" C/C++ completion engine based on clang
Plug 'Rip-Rip/clang_complete'
" Go all-in-all
Plug 'fatih/vim-go'
""" Language independent syntax stuff
Plug 'sheerun/vim-polyglot'
Plug 'justinmk/vim-syntax-extra'
"""License adder
Plug 'antoyo/vim-licenses'
"""find ideal positions to jump to
Plug 'bradford-smith94/quick-scope'
"""comment toggle
Plug 'tpope/vim-commentary'
""" Git related
Plug 'airblade/vim-gitgutter'
Plug 'iberianpig/tig-explorer.vim'
""" Syntax checking
Plug 'w0rp/ale'
""" Auto formatting
Plug 'chiel92/vim-autoformat'
""" Async runner
Plug 'skywind3000/asyncrun.vim'
""" 256 Color theme
Plug 'morhetz/gruvbox'
""" Custom text objects
Plug 'tpope/vim-repeat'
Plug 'ChanderG/TextObjectify'
Plug 'michaeljsmith/vim-indent-object'
Plug 'kana/vim-textobj-user'
Plug 'glts/vim-textobj-comment'
Plug 'kana/vim-textobj-function'
"" Operators
Plug 'machakann/vim-sandwich'
" camel-Snake case helper
Plug 'chaoren/vim-wordmotion'
""" quickfix helpers
Plug 'romainl/vim-qf'
""" LSP
Plug 'natebosch/vim-lsc'
""" Autoclose chars
Plug 'vim-scripts/AutoClose'
""" Snippets
Plug 'KeyboardFire/vim-minisnip'
call plug#end()
" set color scheme
colorscheme gruvbox
"""For the License Adder
let g:licenses_authors_name = 'Govindarajan, Chander <[email protected]>'
let g:licenses_copyright_holders_name = 'Govindarajan, Chander <[email protected]>'
""" set terminal mode
"" DON'T TOUCH THIS VARIABLE - NO OTHER VALUE WORKS
set term=rxvt-unicode
""" this way, by using tmux (with xterm keys on) also works
""" for urxvt
map [5^ <C-PageUp>
map [6^ <C-PageDown>
""" Tabs management
"""switching between tabs
nnoremap <C-PageUp> :tabprevious<CR>
nnoremap <C-PageDown> :tabnext<CR>
""" new tab creation
nnoremap tn :tabnew<CR>
""" Timeouts for commands
set notimeout
set ttimeout
""" Show partial commands
set showcmd
""" A better escape
inoremap <silent> <Left> <ESC><Left>
inoremap <silent> <Right> <ESC><Right>
""" remove highlighting till next search
nnoremap <silent> <esc> :noh<return><esc>
""" Courtesy of nvie/vimrc
""" to paste without mass auto indendation
set pastetoggle=<F2>
""" fold using syntax
set foldmethod=syntax
set foldclose=all "automatically reclose after navigating out
set foldlevel=10
" open close folds with space
nnoremap <space> za
""" underline current line
set cursorline
noremap <silent> <F3> :set nocursorline!<CR>
""" keep para indentation when wrapping text
set breakindent
" Quick yanking to the end of the line
nnoremap Y y$
""" End courtesy
""" slime configuration
let g:slime_target = "tmux"
noremap <silent> X :SlimeSendCurrentLine<CR>
""" Better 'complete'
" i - too slow when ** is in path
" t - usually too many tags;
" in any case can manually trigger one of the above
set complete=.,w,b,u
set completeopt=longest,menu,menuone,preview
"" ale linters
" Require: pylint (apt-get)
" Require: gcc , cppcheck (apt-get), splint(apt-get), clang(apt-get)
let g:ale_linters = {
\ 'python': ['pylint', 'pep8'],
\ 'c': ['gcc','cppcheck','splint','clang_check','clang_tidy'],
\ 'cpp': ['gcc','cppcheck','clang_check','clang_tidy'],
\}
""" Auto formatting
" format on save
au BufWrite *.py :Autoformat
au BufWrite *.c :Autoformat
au BufWrite *.cpp :Autoformat
" python: formatting requries python-autopep8 (apt-get)
" c/c++ : clangformat, comes with clang (apt-get)
""" clang_complete
" Require: clang (apt-get), exact path needs to be put here
let g:clang_library_path='/usr/lib64/llvm/libclang.so'
let g:clang_complete_loaded="0"
""" jedi-vim
let g:jedi#show_call_signatures = "2"
let g:jedi#popup_select_first = 1
""" jump to uses of function using cscope
nnoremap <leader>] :cs find c <C-R>=expand("<cword>")<CR><CR>
""" highlight useless trailing whitespace for removal
highlight ExtraWhiteSpace ctermbg=red
match ExtraWhiteSpace /\s\+$/
""" Easier access to system clipboard
nnoremap <leader>y "*y
nnoremap <leader>p "*p
""" Easy technique for clean alignment
" still need to reindent manually
vnoremap <leader>a !column -t<CR>
" also use the -s flag to manage multi word coumns
""" Home grown CtrlP alternative powered by dmenu--------------------------->
function! DmenuOpen(cmd)
let iname = system(a:cmd . " 2>/dev/null | dmenu -i -f -l 10 -p open")
if empty(iname)
return
endif
execute "e " . iname
endfunction
" files being tracked by git
nnoremap <silent> <C-p> :call DmenuOpen("git ls-files --exclude-standard -co")<cr>
" files currently being tracked in quilt
nnoremap <silent> <C-u> :call DmenuOpen("quilt files")<cr>
" using the normal find command
nnoremap <silent> <C-f> :call DmenuOpen("find . -type f")<cr>
" git files currently tracked with modifications set
nnoremap <silent> <C-e> :call DmenuOpen("(git diff --name-only --cached; git ls-files -m)")<cr>
" old files from viminfo
nnoremap <silent> <Space>o :call DmenuOpen("grep '^>' ~/.viminfo \| cut -c3-")<cr>
" add more as needed !!!
""" ------------------------------------------------------------------------<
""" Home grown register selector powered by dmenu--------------------------->
" Not really using.
function! RegisterView(op)
let save_pos = getpos(".")
let tmpfile = tempname()
execute "redir > " . tmpfile . "|silent registers|redir END"
let rawout = system("cat " . tmpfile . "| dmenu -i -l 15 -p Reg")
execute delete(tmpfile)
call setpos(".", save_pos)
if (empty(rawout)) " for exiting flow if esc is entered from dmenu
return
endif
let reg = split(rawout)[0]
call feedkeys(a:op . reg[1], 'n')
endfunction
" nnoremap <silent> " :call RegisterView("\"")<CR>
""" ------------------------------------------------------------------------<
""" For automatic search of include files etc
" can now jump to local include files in projects
set path+=**
" find the next number
nnoremap <silent> <leader>n /\d\+<CR>
" highlight word under cursor
highlight WordUnder ctermbg=237
autocmd CursorMoved * exe printf('match WordUnder /\V\<%s\>/', escape(expand('<cword>'), '/\'))
" Switching between diff with master and INDEX
let g:gitgutter_diff_target_master = 0
function! GitDiffTargetToggle()
if g:gitgutter_diff_target_master
let g:gitgutter_diff_base = ''
let g:gitgutter_diff_target_master = 0
echom "Showing diff with INDEX"
else
let g:gitgutter_diff_base = 'master'
let g:gitgutter_diff_target_master = 1
echom "Showing diff with master"
endif
GitGutter
endfunction
nnoremap <silent> gM :call GitDiffTargetToggle()<CR>
""" Home grown "helm-mini" --------------------------------------------->
" Switch buffer easily with fuzzy find
" Even simpler alt: nnoremap <Space>b :ls<CR>:b<Space>
" or: nnoremap <Space>b :b<Space><Tab>
" Problem with this: am not really using long lived buffers and C-e already
" covers this use case heavily.
function! BufferSwitch()
let save_pos = getpos(".")
let tmpfile = tempname()
execute "redir > " . tmpfile . "|silent ls|redir END"
let rawout = system("cat " . tmpfile . " | dmenu -i -l 10 -p buffer")
execute delete(tmpfile)
call setpos(".", save_pos)
if (empty(rawout)) " for exiting flow if esc is entered from dmenu
return
endif
let buffer = split(rawout)[0]
execute "b " . buffer
endfunction
nnoremap <silent> <C-y> :call BufferSwitch()<CR>
" ----------------------------------------------------------------------<
""" Home grown line finder using dmenu --------------------------------->
" Like the FZF :Blines command.
function! LineSelect()
let rawout = system("cat -n " . expand('%:p') . " | dmenu -i -l 10 -p line")
if (empty(rawout)) " for exiting flow if esc is entered from dmenu
return
endif
let lineno = split(rawout)[0]
execute lineno
endfunction
noremap <silent> <C-l> :call LineSelect()<CR>
" ----------------------------------------------------------------------<
" use ag if available
if executable("ag")
set grepprg=ag\ --vimgrep
set grepformat=%f:%l:%c:%m,%f:%l:%m
endif
" visual tab characters
set list
set lcs=tab:├─
" set lcs=tab:\|\
" set lcs=tab:▶\
"" gitgutter text objects
" c conflicts with 'comment' text object
omap ih <Plug>GitGutterTextObjectInnerPending
omap ah <Plug>GitGutterTextObjectOuterPending
xmap ih <Plug>GitGutterTextObjectInnerVisual
xmap ah <Plug>GitGutterTextObjectOuterVisual
""" Recently entered words completions
" Complete from list of newly inserted words
" Meant to be used without any prefix; if some prefix is known/entered, normal
" autocomplete, currently neocomplete, will kick in
function! RecentAdditions(findstart, base)
" if first invocation - grab full keyword before cursor
if a:findstart == 1
return match(strpart(getline('.'), 0, col('.')), '\k*$')
endif
" list of words in addition sections in the git diff
let wordlist = split(system('git diff | grep "^+[^+]\{2\}" | cut -c2- | paste -sd " " - | sed "s/[^a-zA-Z0-9_]/\ /g"'))
"" can do additional processing here, like
" 1. filtering out small words
" 2. removing words that already exist in buffer
" right now: keeps words that contain stuff already entered
call filter(wordlist, 'v:val =~ a:base')
return wordlist
endfunction
set completefunc=RecentAdditions
" has to be triggered using C-X C-U
" cleaner form
highlight link Function GruvboxBlue
" comments in italic
highlight Comment cterm=italic
""" Use gtags for everything
" Source gtag functions
source /usr/share/gtags/gtags.vim
" Use gtags instead of cscope (all cscope functions should work out of the
" box)
source /usr/share/gtags/gtags-cscope.vim
" activate cscope db if possible; cscope functions will work after this
silent GtagsCscope
" Use cscope (now actually gtag) for tags instead of (c|e)tags
set cscopetag
""" Home grown one-shot multi substring find.
"" Doing it this way is a bit expensive/slow
" Convert wordstring to regex suitable for substring search
function! SSS(words)
return '.*'.substitute(escape(a:words, '.'), '\s\+', '\\\&.*', &gdefault ? 'gg' : 'g')
endfunction
"" call tag function
function! TagSSS(words)
execute "tag /".SSS(a:words)
endfunction
command! -nargs=* Tag :call TagSSS(<q-args>)
"" list matches in buffer
function! ListSSS(words)
execute "g/" . SSS(a:words) . "\\c"
endfunction
command! -nargs=* LS :call ListSSS(<q-args>)
"" file opening helper
" takes cmd to use to create a list to search for files in
function! FileOpenSSS(cmd, words)
let rawout = split(system(a:cmd), "\n")
execute "e" matchstr(rawout, "\c" . SSS(a:words))
endfunction
command! -nargs=* G :call FileOpenSSS("git ls-files --exclude-standard -co", <q-args>)
command! -nargs=* F :call FileOpenSSS("find . -type f", <q-args>)
"" Mappings for tig-explorer
nnoremap <Space>g :Tig<CR>
nnoremap <Space>b :TigBlame<CR>
""" LSP
let g:lsc_auto_map = v:true " Use defaults
let g:lsc_server_commands = {
\ 'python': 'pyls',
\ 'java': '/home/chanderg/Documents/Dabblings/lsp/jdt_language_server',
\ }
""" Shell/Terminal Workflow
" single escape used by arrow keys internally etc
tnoremap <Esc><Esc> <C-\><C-n>
" Excellent idea for one off shell interactions
" Found here: https://stackoverflow.com/a/7185348
" Works because C-d on bash side brings one back to vim
nnoremap <C-d> :sh<CR>
""" Redirect to buffer
"" Based on https://gist.github.com/romainl/eae0a260ab9c135390c30cd370c20cd7
function! Redir(cmd)
if a:cmd =~ '^!'
execute "let output = system('" . substitute(a:cmd, '^!', '', '') . "')"
else
redir => output
execute a:cmd
redir END
endif
vnew
let w:scratch = 1
setlocal buftype=nofile noswapfile
call setline(1, split(output, "\n"))
" Prompt for name of scratch buffer
call inputsave()
let name = input('Buffer name (empty for default): ')
redraw
if name != ""
execute "file " . name
endif
call inputrestore()
endfunction
command! -nargs=1 -complete=command Redir call Redir(<f-args>)
" vim-go settings
" disable def mapping; use global with gogtags instead
let g:go_def_mapping_enabled = 0
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
""" vim-qf mappings
nmap <space>q <Plug>(qf_qf_toggle)
nmap <space>l <Plug>(qf_loc_toggle)
nmap [q <Plug>(qf_qf_previous)
nmap ]q <Plug>(qf_qf_next)
nmap [l <Plug>(qf_loc_previous)
nmap ]l <Plug>(qf_loc_next)
" restore CR for quickfix
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
autocmd BufReadPost quickfix nnoremap <buffer> D :Reject<CR>
""" comment line with duplicate
nnoremap zz yygccp
"""------------------------------------------------------------------------------------->
""" Vim Script Vimball installer
"" Install into .vim without special rtp changes
"" Save a copy of all vimballs in ~/.vim/vimscripts
" global dict of vim scripts
let vim_scripts = {}
function! VimScript(scriptname, fileno)
let g:vim_scripts[a:scriptname] = a:fileno
endfunction
" Install vimscript by name, fileno
function! VimScriptInstallScript(scriptname, fileno)
silent !mkdir -p ~/.vim/vimscripts
let exists = system("ls ~/.vim/vimscripts | grep " . a:scriptname . ".vmb")
if empty(exists)
echom "Installing " . a:scriptname
execute "silent !wget https://www.vim.org/scripts/download_script.php?src_id=" . a:fileno . " -O ~/.vim/vimscripts/" . a:scriptname . ".vmb.gz"
execute "silent !gunzip ~/.vim/vimscripts/" . a:scriptname . ".vmb.gz"
execute "source ~/.vim/vimscripts/" . a:scriptname . ".vmb"
else
echom "Skipping " . a:scriptname
endif
endfunction
" install all registered vim scripts
function! VimScriptInstall()
for item in items(g:vim_scripts)
call VimScriptInstallScript(item[0], item[1])
endfor
echom "Done installing Vim Scripts."
endfunction
"" handy command for the above
command! -nargs=0 VimScriptInstall call VimScriptInstall()
""" End VimScript installer
"""-------------------------------------------------------------------------------------<
"" Register required vimscripts
call VimScript("ReplaceWithRegister", 22581)
""" Default textobjectify mapping.
let g:textobjectify = {
\'(': {'left': '(', 'right': ')', 'same': 0, 'seek': 1, 'line': 0},
\')': {'left': '(', 'right': ')', 'same': 0, 'seek': 2, 'line': 0},
\'{': {'left': '{', 'right': '}', 'same': 0, 'seek': 1, 'line': 0},
\'}': {'left': '{', 'right': '}', 'same': 0, 'seek': 2, 'line': 0},
\'[': {'left': '\[', 'right': '\]', 'same': 0, 'seek': 1, 'line': 0},
\']': {'left': '\[', 'right': '\]', 'same': 0, 'seek': 2, 'line': 0},
\'<': {'left': '<', 'right': '>', 'same': 0, 'seek': 1, 'line': 0},
\'>': {'left': '<', 'right': '>', 'same': 0, 'seek': 2, 'line': 0},
\'"': {'left': '"', 'right': '"', 'same': 1, 'seek': 1, 'line': 0},
\"'": {'left': "'", 'right': "'", 'same': 1, 'seek': 1, 'line': 0},
\'`': {'left': '`', 'right': '`', 'same': 1, 'seek': 1, 'line': 0},
\'V': {'left': '^\s*\(if\|for\|function\|try\|while\)\>',
\'right': '^\s*end', 'same': 0, 'seek': 1, 'line': 1},
\"\<cr>": {'left': '\%^', 'right': '\%$', 'same': 0, 'seek': 0,
\'line': 0},
\}
""" Text objects for function arguments
let g:textobjectify['a'] = {'left': '(', 'right': ')\|,', 'same': 0, 'seek': 1, 'line': 0}
let g:textobjectify['A'] = {'left': ',\|(', 'right': ')', 'same': 0, 'seek': 1, 'line': 0}
""" Text object for anything between 2 punctuations
let g:textobjectify['u'] = {'left': '[.=:]', 'right': '[.=:]', 'same': 0, 'seek': 1, 'line': 0}
""" Experimental "indentpara" text object using kana/vim-textobj-user
"" Implies the current paragraph but only lines of the current indent or above
call textobj#user#plugin('indentpara', {
\ 'indentpara': {
\ 'select-i': 'iz',
\ 'select-i-function': 'CurrentIndentPara',
\ },
\})
function! CurrentIndentPara()
" get starting column num of this line
normal! ^
let indentcol = getpos('.')[2]
" go to start of para and search down for first line that matches indent
normal! {
call search('^\s*\%'.indentcol.'c', 'W')
let head_pos = getpos('.')
" go to end of para and search up for first line that matches indent
normal! }
call search('^\s*\%'.indentcol.'c', 'b')
let tail_pos = getpos('.')
return ['V', head_pos, tail_pos]
endfunction
""" End "indentpara" text object