-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc_2022
436 lines (357 loc) · 14.1 KB
/
vimrc_2022
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
" plug autoinstalltion
if empty(glob("~/.vim/autoload/plug.vim"))
execute '!mkdir -p ~/.vim/autoload'
execute '!curl -fLo ~/.vim/autoload/plug.vim https://raw.github.com/junegunn/vim-plug/master/plug.vim'
endif
inoremap jj <ESC>
nmap <c-x> :silent! python3 import re,vim,subprocess;subprocess.call(['tmux', 'send-keys', '-t', '1', re.sub(r';\s*$', '\\;', vim.current.line).replace('\t',' '), 'enter'])<cr>j
vmap <c-x> :silent! python3 import re,vim,subprocess;subprocess.call(['tmux', 'send-keys', '-t', '1', re.sub(r';\s*$', '\\;', '\n'.join(vim.current.range)).replace('\t',' '), 'enter'])<cr>
"set bg=dark
call plug#begin()
Plug 'rking/ag.vim'
Plug 'scrooloose/nerdtree'
Plug 'fatih/vim-go'
" apt install universal-ctags # NOT excuberent tags for yaml support
Plug 'majutsushi/tagbar'
"Plug 'kien/ctrlp.vim' " depreacted
Plug 'ctrlpvim/ctrlp.vim'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-fugitive'
Plug 'junkblocker/git-time-lapse'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-repeat'
Plug 'stephpy/vim-yaml'
Plug 'pedrohdz/vim-yaml-folds'
Plug 'will133/vim-dirdiff'
Plug 'joe-skb7/cscope-maps'
"Plug 'daylerees/colour-schemes', {'rtp':'vim'}
" comment with gcc
Plug 'tomtom/tcomment_vim'
Plug 'towolf/vim-helm' " breaks expandtab,ts,tw for yaml
" LSP
" let g:lsp_auto_enable = 1 # modify this to work below !!! 0
"vim-lsp-settings breaks c-d scrolling !!!!
Plug 'prabirshrestha/vim-lsp'
Plug 'mattn/vim-lsp-settings'
Plug 'rhysd/vim-healthcheck' " :CheckHealth
" macro fodling/highlighing
"Plug 'mphe/grayout.vim'
"Plug 'krzbe/vim-lsp-inactive-regions'
call plug#end()
" Ex mode disable
" https://vi.stackexchange.com/questions/457/does-ex-mode-have-any-practical-use
nnoremap Q <nop>
" https://vim.fandom.com/wiki/Identify_the_syntax_highlighting_group_used_at_the_cursor
nnoremap <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" dir diff
"set splitbelow
set foldlevel=99
nnoremap <F2> :NERDTreeToggle<CR>
let g:go_version_warning = 0
map <F3> :CtrlPBufTag<CR>
map <F4> :let g:ctrlp_mruf_relative=1<bar>CtrlPMRUFiles<CR>
map <leader><F4> :let g:ctrlp_mruf_relative=0<bar>CtrlPMRUFiles<CR>
map <F5> :CtrlPTag<CR>
set nocompatible
set backspace=indent,eol,start
set nowrap
set noswapfile
" S for subsitute inner word from yanked text
" change inner word and in insert mode yank from " and exit inster mode :)
nnoremap <leader>s "_ciw<c-r>"<esc>
vnoremap <leader>s "_dP
" Run last commend in 1 tmux window
nmap <leader>r :up<bar>python3 import vim,subprocess;subprocess.call(['tmux', 'send-keys', '-t', '1', 'c-p', 'enter'])<cr>
"nmap <leader>R :up<bar>python3 import vim,subprocess;subprocess.call(['tmux', 'send-keys', '-t', '1', ', 'c-p', 'enter'])<cr>
" Ipython
nmap <leader>ip o__import__('IPython').embed()<ESC>:w<cr>
nmap <leader>ib o__import__('ipdb').set_trace()<ESC>:w<cr>
au FileType json set foldmethod=syntax
" FOR asyncio code
" https://stackoverflow.com/questions/56415470/calling-ipython-embed-in-asynchronous-code-specifying-the-event-loop
" import os;
" os.system('pip install IPython nest-asyncio')
" import nest_asyncio
" nest_asyncio.apply()
" __import__('IPython').embed(using='asyncio')
""" ------ sudo write
command! W w !sudo tee % > /dev/null
function! Mouseon()
set mouse=a
" for better scrolling when using the mouse
set scrolloff=2
" Toolbar
" set guioptions+=T
" for better golang navigation
" TO PSUJE scrollowanie
map <C-LeftMouse> gd
nmap <RightMouse> <c-o>
nmap <2-LeftMouse> gd
" nmap <expr> <2-LeftMouse> (&buftype is# "quickfix" ? "" : "gd")
endfunction
call Mouseon()
map <silent> <F2> :NERDTreeToggle<CR>
map <silent> <leader><F2> :NERDTreeFind<CR>
let NERDTreeShowBookmarks = 0
let NERDChristmasTree = 0
" set Enter/Return to activate a node
let NERDTreeMapActivateNode='<CR>'
" always change CWD
let NERDTreeChDirMode = 2
" more colors
let NERDTreeMinimalUI = 1
"let NERDTreeDirArrows=1
let NERDTreeQuitOnOpen = 0
let NERDTreeIgnore = ['\.pyc$', '\~$', '\.o$', '__pycache__', '_test\.go$']
let NERDTreeMouseMode = 3
nnoremap <leader>f *N
" for visual use //
set hlsearch
map <leader>/ :nohlsearch<cr>
""" tagbar
map <leader><F3> :TagbarToggle<CR>
let g:tagbar_autofocus = 1
let g:tagbar_autoclose = 0
let g:tagbar_width = 80
""" ctags
map <F8> :!ctags --verbose=no --totals --recurse=yes<cr>
map <F9> :!ctags --verbose=no --totals %<cr>
map <leader><F8> :!/root/ppalucki/dotfiles/cscope_gen.sh<cr>:cscope kill -1<cr>:cscope add cscope.out<cr>:cscope show<cr>
au FileType go map <buffer> <F8> :!gotags -R -f tags \.<cr>
au FileType python map <buffer> <F8> :!ctags -f _tags --languages=Python --verbose=no --totals --recurse=yes --exclude=tmp --exclude=env --exclude=.venv --fields=zK ;fgrep -v kind:variable _tags <bar> fgrep -v kind:i <bar> fgrep -v kind:namespace >tags;rm _tags; ls -l tags; wc -l tags<cr>
""" python folding
" check commented line about folding using LSPFOLDING
au FileType python set foldmethod=indent
" 1) for large projects like Kubernetes used following trick manually: only " pkg/cmd so no vendor/third_party
" and exclude tests and generated files (reduces numbers of tags from 500k to 40-60k)
" find -path './cmd*' -or -path './pkg*' ! -name '*_test.go' ! -name '*generated*' | gotags -L - >tags
" 2) for single file
" :!ctags %
""" cscope
" http://cscope.sourceforge.net/cscope_maps.vim
" http://cscope.sourceforge.net/cscope_vim_tutorial.html
" generate tags ~/ppalucki/dotfiles/cscope_gen.sh
" use copen instead of query dialog
" The following maps all invoke one of the following cscope search types:
" ctrl-\ (current window) then:
" ctrl-spacebar (vertical split) then:
" ctrl-space-space (horizonatl split) then:
" 's' symbol: find all references to the token under cursor
" 'g' global: find global definition(s) of the token under cursor
" 'c' calls: find all calls to the function name under cursor
" 't' text: find all instances of the text under cursor
" 'e' egrep: egrep search for the word under cursor
" 'f' file: open the filename under cursor
" 'i' includes: find files that include the filename under cursor
" 'd' called: find functions that function under cursor calls
"use [q ]q or copen for navigation
set cscopequickfix=s-,g-,d-,c-
""" move between windows
nmap <C-J> <C-W>j
nmap <C-K> <C-W>k
nmap <C-l> <C-W>l
nmap <C-h> <C-W>h
let mapleader = "\\"
map <space> \
filetype plugin indent on
syntax on
set hidden
""" ---- saveall shortcut
map ZW :wall<CR>
map ZA :qa<CR>
""" write/quit
" aka ZZ
map <leader>x :close<CR>
map <leader>w :silent up<CR>
map <leader>W :silent w!<CR>
map <leader>q :qa<CR>
" " aka ZQ
map <leader>Q :qa!<CR>
" Jump to next/previous merge conflict marker [C conflicts with vim-unimparied
nnoremap <silent> ]d /\v^(\<\|\=\|\>){7}([^=].+)?$<CR>
nnoremap <silent> [d ?\v^(\<\|\=\|\>){7}([^=].+)\?$<CR>
augroup resCur
autocmd!
autocmd BufWinEnter * call setpos(".", getpos("'\""))
augroup END
" Open last/alternate buffer
noremap <Leader><Leader> <C-^>
noremap <Leader><space> <C-^>
" " 'edit alternate file' convenience mapping
"nnoremap <BS> <C-^>
"
" search search raw text plain [find]
" http://vim.wikia.com/wiki/Searching_for_expressions_which_include_slashes
command! -nargs=1 SS let @/ = '\V'.escape(<q-args>, '/\')|normal! /<C-R>/<CR>
" visual search selected text [find]
" http://vim.wikia.com/wiki/Search_for_visually_selected_text
" vnoremap // y/<C-R>"<CR>"
vnoremap // y:SS <C-R>"<CR>
vnoremap <leader>f y:SS <C-R>"<cr>N
""" ------------ replace ---------------------
""" 1) Search (h) in multiple files
""" 2) Search and Replace (y) in single file
""" 3) Search and Replace (u) in multiple files
""" ---------------------------------------------------------
" replace normal mode with last searched element elmenet
" nmap <leader>y :.,$s///gc<left><left><left>
""" 1) Search (h)
map <leader>h "ayiw:Ag! -- "<C-r>a"
vmap <leader>h "ay:Ag! -- "<C-r>a"
map <leader>H "ayiw:Ag! --all-types --skip-vcs-ignores -- "<C-r>a"
vmap <leader>H "ay:Ag! --all-types --skip-vcs-ignores -- "<C-r>a"
""" 2) Search and Replace (y) in single file
nmap <leader>y :%s///gc<left><left><left>
" replace last searched element ("/ register) in given selection
vmap <leader>y :s///gc<left><left><left>
" replaced visually selected element in whole document
vmap <leader>Y y<bar>:%s/<c-r>"/<c-r>"/gc<left><left><left>
" replaced visually selected element in all files from quick files list -
" first use <leader>h to findall files
vmap <leader>u y<bar>:cfdo %s/<c-r>"/<c-r>"/gc<left><left><left>
""" 3) Search and Replace (u) in multiple files
map <leader>u "ayiw:Ag! -- "<C-r>a"<cr><bar>:cfdo %s/<c-r>a/<c-r>a/gc<left><left><left>
vmap <leader>u "ay:Ag! -- "<C-r>a"<cr><bar>:cfdo %s/<c-r>a/<c-r>a/gc<left><left><left>
map <leader>U "ayiw:Ag! --all-types -- "<C-r>a<cr><bar>:cfdo %s/<c-r>a/<c-r>a/gc<left><left><left>
vmap <leader>U "ay:Ag! --all-types -- "<C-r>a"<cr><bar>:cfdo %s/<c-r>a/<c-r>a/gc<left><left><left>
" default size to see full folder names
let g:NERDTreeWinSize=60
nmap cp :let @" = expand("%:p")<bar>echo @"<cr>
""" Fugitive
map <leader>c :Git<cr>
map <leader>e :e ~/.vimrc<cr>
map <leader>d :Gdiffsplit!<cr>
" folding for CPP
function! FoldtextForC()
" Show the whole #if line
"return getline(v:foldstart)
return printf("+%s %s", v:folddashes, getline(v:foldstart))
endfun
function! FoldPreprocessor()
"set foldmarker=#if,#endif,#else
"set foldmethod=marker
set foldtext=FoldtextForC()
set foldmarker=#if,#endif
set foldmethod=marker
endfunction
autocmd FileType cpp call FoldPreprocessor()
""" CPP
au FileType cpp set ts=4 sw=4 et
au FileType cmake set ts=4 sw=4 et
""" markdown (similar to yaml configuration)
au FileType markdown set ts=2 sw=2 et
""" yaml manuall
"au FileType yaml set ts=2 sw=2 et foldmethod=indent
"""" LSP Configuration
" enable lsp on startup (1) or disable (0)
" works well for
" go - gopls
" yaml - yaml-language-server
" python - pylsp-all
let g:lsp_auto_enable = 1
let g:lsp_settings = {
\ 'yaml-language-server': { 'disabled': 1, },
\ 'gopls': { 'disabled': 0, },
\ 'pylsp-all': { 'disabled': 0, },
\ 'helm-ls': { 'disabled': 0, },
\}
"au FileType yaml call lsp#activate()
"au FileType python let g:lsp_auto_enable = 1
"au FileType go let g:lsp_auto_enable = 1
" disable everything - I usually need just gd and K
let g:lsp_diagnostics_enabled = 0 " diagnostics: disable diagnosctics warn/error https://github.com/prabirshrestha/vim-lsp?tab=readme-ov-file#diagnostics
let g:lsp_diagnostics_echo_cursor = 1
let g:lsp_diagnostics_signs_enabled = 0 " diagnostics signs warnings/errors
let g:lsp_diagnostics_virtual_text_enabled = 0 " diagnostics virtual text - use the one below from status bar
let g:lsp_document_highlight_enabled = 0 " disable highlight refrences https://github.com/prabirshrestha/vim-lsp?tab=readme-ov-file#highlight-references
let g:lsp_completion_documentation_enabled = 0
let g:lsp_signature_help_enabled = 0
let g:lsp_format_sync_timeout = 1000
let g:lsp_fold_enabled = 0 " disable if it doesnt work!
" debugging
let g:lsp_log_verbose = 0
let g:lsp_log_file = expand('~/vim-lsp.log')
""" LSP bindings
function! s:on_lsp_buffer_enabled() abort
if exists('+tagfunc') | setlocal tagfunc=lsp#tagfunc | endif
nmap <buffer> gd <plug>(lsp-definition)
nmap <buffer> gs <plug>(lsp-document-symbol-search)
nmap <buffer> gS <plug>(lsp-workspace-symbol-search)
nmap <buffer> gr <plug>(lsp-references)
nmap <buffer> gi <plug>(lsp-implementation)
nmap <buffer> gt <plug>(lsp-type-definition)
nmap <buffer> <leader>rn <plug>(lsp-rename)
nmap <buffer> [g <plug>(lsp-previous-diagnostic)
nmap <buffer> ]g <plug>(lsp-next-diagnostic)
nmap <buffer> K <plug>(lsp-hover)
"nnoremap <buffer> <expr><c-f> lsp#scroll(+4)
"nnoremap <buffer> <expr><c-d> lsp#scroll(-4)
" autocmd! BufWritePre *.rs,*.go call execute('LspDocumentFormatSync')
" refer to doc to add more commands
" https://github.com/prabirshrestha/vim-lsp?tab=readme-ov-file#folding
" LSPFOLDING DOESNOt WORK with c++/clangd
"let g:lsp_fold_enabled = 1 " disable if it doesnt work!
"set foldmethod=expr foldexpr=lsp#ui#vim#folding#foldexpr() foldtext=lsp#ui#vim#folding#foldtext()
" LSPTAGS
"autocmd FileType python setlocal tagfunc=lsp#tagfunc
setlocal tagfunc=lsp#tagfunc
" LSPCOMPLETE (use C-x C-o)
" h omnifunc
" h ins-completion
"autocmd FileType python setlocal omnifunc=lsp#complete
setlocal omnifunc=lsp#complete
" LSPSIGNs
setlocal signcolumn=no
endfunction
augroup lsp_install
au!
" call s:on_lsp_buffer_enabled only for languages that has the server registered.
autocmd User lsp_buffer_enabled call s:on_lsp_buffer_enabled()
augroup END
""" vim-helm
au FileType helm set ts=2 sw=2 et
call tcomment#type#Define('helm','# %s')
""" vim-go
au FileType go set ts=4 sw=4 et
""" shell expandtab and
" sw? = shiftwidth - INSERTING - Number of spaces to use for each step of (auto)indent. Used for |'cindent'|, |>>|, |<<|, etc.
" ts? = tabstop - LOOK - Number of spaces that a <Tab> in the file counts for
au FileType sh set expandtab ts=2 sw=2
""" Trailing space remove
" https://vi.stackexchange.com/questions/454/whats-the-simplest-way-to-strip-trailing-whitespace-from-all-lines-in-a-file
"Remove all trailing whitespace by pressing F12
nnoremap <F12> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar><CR>
""" COLORS (must be at the end!!!!)
" configure with calling :hi
set termguicolors
set t_Co=256
set term=xterm-256color
silent colorscheme slate
hi Comment guifg=#888888
"hi PreProc term=underline ctermfg=9 guifg=red guibg=white
"hi PreProc guibg=DarkGrey
"hi PreProc guibg=bg
hi clear PreProc
" https://github.com/preservim/tagbar/wiki#yaml
let g:tagbar_type_yaml = {
\ 'ctagstype' : 'yaml',
\ 'kinds' : [
\ 'a:anchors',
\ 's:section',
\ 'e:entry'
\ ],
\ 'sro' : '.',
\ 'scope2kind': {
\ 'section': 's',
\ 'entry': 'e'
\ },
\ 'kind2scope': {
\ 's': 'section',
\ 'e': 'entry'
\ },
\ 'sort' : 0
\ }
" DirDiff excludes
let g:DirDiffExcludes = "CVS,*.class,*.exe,.*.swp,*.pyc,*.pb"