-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_vimrc
More file actions
561 lines (512 loc) · 15.6 KB
/
_vimrc
File metadata and controls
561 lines (512 loc) · 15.6 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
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
" ENVIRONMENT VARS
" LLVM_DIR
filetype plugin on
"Plugins{{{
"download vimplug and put in autoload directory
call plug#begin('~/vimfiles/plugged')
Plug 'scrooloose/nerdtree'
Plug 'udalov/kotlin-vim'
Plug 'vim-jp/vim-cpp'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'majutsushi/tagbar'
"Plug 'danielwe/base16-vim'
Plug 'sainnhe/gruvbox-material'
Plug 'scrooloose/nerdcommenter'
Plug 'mhinz/vim-startify'
call plug#end()
"}}}
set go-=r
set ffs=unix,dos
let &statusline="\ \ \ \ %{expand('%:p:h')}\\"
set stl+=%#FileNameHL#
set stl+=%t
set stl+=%#StatusLine#
set stl+=\ Buf:%n
set statusline+=%=
set statusline+=%m\ chr=0x%02.2B\ byte_no=%o\ L=%02l\ C=%02c\ [%p%%]
set titlestring=%F\ %m[%p%%]
syntax on
set mousefocus
let g:NERDCustomDelimiters = { 'dosini': { 'left':'#'} }
"Variables
let LLVM_DIR = $LLVM_DIR
"Notes {{{
"
"q: -- enter command window
"
"C-l for refreshing the screen
"
"redir @* | set guifont? | redir END
"
"For easier diffing execute these in corresponding splits
" ;set cursorbind
" :set scrollbind
"}}}
vnoremap <leader>" <esc>`<i"<esc>`>a"<esc>
nnoremap <leader>" viw<esc>a"<esc>bi"<esc>lel
iabbrev #i #include <><left>
set autoread
if has('gui_running')
set cursorline
endif
let g:tagbar_show_linenumbers=1
let NERDTreeShowLineNumbers=1
let NERDTreeChDirMode=2
set undofile
" TODO: fix this
if has("unix")
set undodir=~/.vimundodir
set dir=~/.vimswap
set backupdir=~/.vimbackups
silent ":!mkdir -p " . dir
silent ":!mkdir -p " . undodir
silent ":!mkdir -p " . backupdir
else
set undodir=$USERPROFILE\.vimundodir
set dir=$USERPROFILE\.vimswap
set backupdir=$USERPROFILE\.vimbackups
silent ":!md " . &dir
silent ":!md " . &undodir
silent ":!md " . &backupdir
endif
let extension = expand('%:e')
if extension == "py"
set foldmethod=indent
else
set foldmethod=syntax
endif
if has("gui_running")
"colorscheme base16-gruvbox-dark-soft
colorscheme gruvbox-material
set background=light
if has("win32")
set rop=type:directx
endif
"This is a workaround for window size change when sourcing vimrc
"i.e. we only set font if it is not already set (on a startup)
let font = execute('set guifont?')
let font = substitute(substitute(font, '\n', '', ''), ' \+guifont', 'guifont', '')
if has("win32")
if font != "guifont=Hack:h15:cANSI"
set guifont=Hack:h15:cANSI
endif
else
if font != "guifont=Hack-Regular:h15"
set guifont=Hack-Regular:h15
endif
endif
endif
set encoding=utf-8 "needed to display cyrillic chars
hi FileNameHL guibg=#b8bb26 guifg=#3c3836
set hidden
noremap <C-j> :bp <CR>
noremap <C-k> :bn <CR>
command! W w
command! Q qall
let mapleader = " " "space
"guiopts {{{
set guioptions-=T " Remove toolbar
set guioptions-=m " Remove menu
set guioptions+=c " Use console for simple choices
set guioptions-=r " remove right scrollbar
set guioptions-=L " Remove left scrollbar
"}}}
set smarttab
set smartindent
set tabstop=4
set shiftwidth=4
set virtualedit=block
set shiftround
set nu rnu
set ls=2
set hlsearch
set expandtab
set incsearch
set scrolloff=99999
au BufRead * silent! lcd %:p:h | set tag=tags;/
if !has("unix")
au GUIEnter * simalt ~x
endif
ino <C-C> <Esc>
au FocusLost * silent! :w
set autochdir
set formatoptions=qrn1
set colorcolumn=79
set display+=lastline " Show as much as possible of the lsat line
"Compilation/building {{{
function! CompileCppFile()
silent w
if has("win32")
!"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\vcvarsamd64_x86.bat" && cl.exe % /std:c++17 /nologo /Fa%:r.exe 2>quickfixerrorfile
"/Fo %:r.exe
"silent !g++ % -march=native -g3 -O0 --std=c++1z -Werror -Wall -pedantic -o %:r.exe 2>quickfixerrorfile
else
if $HAS_GCC
silent !g++ % -march=native -g3 -O0 --std=c++1z -Werror -Wall -pedantic -o %:r.exe 2>quickfixerrorfile
else
silent !clang++ % -march=native -Xclang -flto-visibility-public-std -g3 -O0 --std=c++1z -Werror -Wall -Wno-format-security -pedantic -o %:r.exe 2>quickfixerrorfile
endif
endif
silent cfile quickfixerrorfile
if !empty(readfile("quickfixerrorfile"))
let g:quickfix_return_to_window = winnr()
copen
execute g:quickfix_return_to_window . "wincmd w"
let g:quickfix_is_open = 1
else
silent !rd quickfixerrorfile
echo "No errors found."
cclose
let g:quickfix_is_open = 0
!%:r
endif
silent !rm quickfixerrorfile
endfunction
function! CompilePython()
silent w
:!python %
endfunction
function! CompileKotlin()
silent w
:!kotlinc % -include-runtime -d %:r.jar && java -jar %:r.jar
":!java -jar %:r.jar
endfunction
function! RunKotlin()
silent w
:!kotlinc -script %
endfunction
function! CompilePythonWithParam()
silent w
let f = input ("arg: ")
:exec "!python % " . f
endfunction
function! RunBatWithParam()
silent w
let f = input ("arg: ")
:exec "!% " . f
endfunction
function! RunPythonInterp()
silent w
:!python -i %
endfunction
function! PandocConv()
:silent exec "!pandoc % -s --toc --toc-depth=4 --css pandoc.css -f gfm -o %:r.md.html"
endfunction
function! IsNERDTreeOpen()
return exists("t:NERDTreeBufName") && (bufwinnr(t:NERDTreeBufName) != -1)
endfunction
function! SyncTree()
if &modifiable && IsNERDTreeOpen() && strlen(expand('%')) > 0 && !&diff
NERDTreeFind
wincmd p
endif
endfunction
set splitbelow
function! CppOutFinished(channel)
ccl
execute "10sp " . g:outName
normal G
if line('$') == 1 && getline(1) == ''
bd
echo 'Finished'
endif
endfunction
function! CompileCppAsyncFinished(channel)
execute "cfile " . g:backgroundCommandOutput
copen
unlet g:backgroundCommandOutput
if line('$') == 1 && getline(1) == ''
bd
let g:outName = tempname() . "_OUT"
call job_start( g:execname, {'close_cb': 'CppOutFinished', "out_io":"file", 'out_name':g:outName})
else
call feedkeys("\<C-w>\<C-p>")
endif
endfunction
function! GetBufferList()
return filter(range(1,bufnr('$')), 'buflisted(v:val)')
endfunction
function! GetMatchingBuffers(pattern)
return filter(GetBufferList(), 'bufname(v:val) =~ a:pattern')
endfunction
function! WipeMatchingBuffers(pattern)
let l:matchList = GetMatchingBuffers(a:pattern)
let l:count = len(l:matchList)
if l:count < 1
"echo 'No buffers found matching pattern ' . a:pattern
return
endif
exec 'bw ' . join(l:matchList, ' ')
"echo 'Wiped ' . l:count . ' buffer' . l:suffix . '.'
endfunction
function! CompileCppBuildBatAsyncFinished(job, exit_status)
execute "cfile " . g:backgroundCommandOutput
copen
if line('$') == 1 && getline(1) == ''
bd
echom g:backgroundCommandOutputBatFile
execute "10sp " . g:backgroundCommandOutputBatFile
normal G
if line('$') == 1 && getline(1) == ''
bd
echo 'Finished'
else
execute ":e ++ff=dos"
endif
else
call feedkeys("\<C-w>\<C-p>")
endif
unlet g:backgroundCommandOutput
unlet g:backgroundCommandOutputBatFile
endfunction
function! FindInUpperDir(filename)
let prev_cwd = getcwd()
let saved_cwd = getcwd()
while !filereadable(a:filename)
cd ../
if prev_cwd == getcwd()
break
endif
let prev_cwd = getcwd()
endwhile
let found = getcwd()
execute "cd " . saved_cwd
if filereadable(found . '/' . a:filename)
return found
else
return ''
endif
endfunction
function! CompileCppBuildBatAsync()
if v:version < 800
echoerr 'Async compilation requires VIM version 8 or higher'
return
endif
call WipeMatchingBuffers(".*tmp_OUT$")
let script_name = 'build.bat'
let script_dir = FindInUpperDir(script_name)
if !filereadable(script_dir . '/' . script_name)
echo "No build.bat is found"
return
endif
if exists('g:backgroundCommandOutput') || exists('g:backgroundCommandOutputBatFile')
echo 'Already compiling in background'
else
echo 'Compiling...'
let g:backgroundCommandOutput = tempname() . "_OUT"
let g:backgroundCommandOutputBatFile = tempname() . "_OUT"
let g:job = job_start([script_dir . '/' . script_name], {'exit_cb': 'CompileCppBuildBatAsyncFinished', "out_io":"file", "out_name":g:backgroundCommandOutputBatFile, "err_io":"file", 'err_name':g:backgroundCommandOutput, 'cwd':script_dir})
execute "cd " . script_dir
let job_status = job_status(g:job)
if job_status == 'fail'
unlet g:backgroundCommandOutput
unlet g:backgroundCommandOutputBatFile
echom "Job start failed!"
endif
endif
endfunction
func! StopJob()
call job_stop(g:job)
echo "Job stopped"
endfunc
function! CompileCppAsync()
silent w
if v:version < 800
echoerr 'Async compilation requires VIM version 8 or higher'
return
endif
call WipeMatchingBuffers(".*tmp_OUT$")
if exists('g:backgroundCommandOutput')
echo 'Already compiling in background'
else
echo 'Compiling...'
let g:backgroundCommandOutput = tempname() . "_OUT"
if $HAS_GCC
let l:compiler = "g++"
let l:compiler_specific_opts = []
else
let l:compiler = "clang++"
let l:compiler_specific_opts = ['-Xclang', '-flto-visibility-public-std']
endif
let g:filename = expand('%')
let g:execname = expand('%:r') . ".exe"
let l:lst = [l:compiler, g:filename, '-march=native', '-g3', '-O0', '--std=c++17', '-Werror', '-Wall', '-Wno-format-security', '-pedantic', '-o', g:execname]
for el in l:compiler_specific_opts
call add(l:lst, el)
endfor
call job_start(l:lst, {'close_cb': 'CompileCppAsyncFinished', "err_io":"file", 'err_name':g:backgroundCommandOutput})
endif
endfunction
function! CompileWithTerminal()
if v:version < 800
echoerr 'Async compilation requires VIM version 8 or higher'
return
endif
let script_name = 'build.bat'
let script_dir = FindInUpperDir(script_name)
if !filereadable(script_dir . '/' . script_name)
echo "No build.bat is found"
return
endif
execute ("!cd " . script_dir . ' && ' . script_name)
endfunction
"}}}
nnoremap <C-F10> :call CompileWithTerminal()<CR>
nnoremap <F10> :call CompileCppBuildBatAsync()<CR>
nnoremap <F11> :call StopJob()<CR>
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal foldmethod=marker
augroup END
augroup Build
autocmd!
autocmd BufEnter *.md
\ set tabstop=2
\ | set shiftwidth=2
autocmd BufEnter *.bat nnoremap <buffer> <F5> :!% <CR>
autocmd BufEnter *.bat nnoremap <buffer> <F6> :call RunBatWithParam() <CR>
autocmd BufEnter *.cpp nnoremap <buffer> <F5> :call CompileCppFile()<CR>
autocmd BufEnter *.cpp nnoremap <buffer> <F6> :!build.bat<CR>
autocmd BufEnter *.cpp nnoremap <buffer> <F9> :call CompileCppAsync()<CR>
autocmd BufEnter *.py nnoremap <buffer> <F5> :call CompilePython() <CR>
autocmd BufEnter *.py nnoremap <buffer> <F6> :call CompilePythonWithParam() <CR>
autocmd BufEnter *.dot nnoremap <buffer> <F5> :!dot -Tpng % -o %:r.png <CR>
autocmd BufEnter *.kt nnoremap <buffer> <F5> :call CompileKotlin() <CR>
autocmd BufEnter *.kts nnoremap <buffer> <F5> :call RunKotlin() <CR>
"requires pandoc and TamperMonkey
"Use this script in TamperMonkey:
"// ==UserScript==
"// @name New Userscript
"// @namespace http://tampermonkey.net/
"// @version 0.1
"// @description try to take over the world!
"// @author You
"// @match http://*/*
"// @grant none
"// ==/UserScript==
"
"(function() {
" 'use strict';
"setTimeout(function(){
" window.location.reload(1);
"}, 500);
" // Your code here...
"})();
"And put this filter into User includes: file//*.md.html
"And Exclude http://*//
" autocmd BufWritePost *.md :call PandocConv()
augroup END
function! QuickfixToggle()
if g:quickfix_is_open
cclose
let g:quickfix_is_open = 0
execute g:quickfix_return_to_window . "wincmd w"
else
let g:quickfix_return_to_window = winnr()
copen
execute g:quickfix_return_to_window . "wincmd w"
let g:quickfix_is_open = 1
endif
endfunction
set path+=**
set wildmenu
let NERDTreeWinSize=25
function! FormatFile()
let FMT = g:LLVM_DIR . "/share/clang/clang-format.py"
let l:lines="all"
:execute("py3f " . FMT)
endfunction
noremap <M-i> :call FormatFile()<CR>
setlocal foldmethod=expr foldexpr=DiffFold(v:lnum)
function! DiffFold(lnum)
let line = getline(a:lnum)
if line =~ '^\(diff\|---\|+++\|@@\) '
return 1
elseif line[0] =~ '[-+ ]'
return 2
else
return 0
endif
endfunction
function! CheckHeaderSource()
if expand("%:e") == "cpp"
let exts = ["h", "hpp"]
let fldrs = ["Inc", "inc", "include"]
else
let exts = ["c", "cpp"]
let fldrs = ["Src", "src", "source"]
endif
for fldr in fldrs
for ext in exts
let l_fname = expand('%:r')
let here = expand('%:p:h') . "/" . l_fname . "." . ext
let there = expand('%:p:h') . "/../" . fldr . "/" . l_fname . "." . ext
"TODO: use substitute
if filereadable(here)
execute "e " . here
elseif filereadable(there)
execute "e " . there
endif
endfor
endfor
endfunction
function! TTakeInput()
let f = input ("Exec: ")
:exec ":!python -c \"print(".f.")\""
endfunction
function! EnterNotes()
silent e $USERPROFILE/notes.txt
:execute "normal G"
:put = strftime('%c')
:put = strftime('-------------------')
:execute "normal! o"
:startinsert!
endfunction
noremap <C-S-F2> :execute "!start ." <CR>
noremap <C-F2> :!start cmd.exe <CR>
noremap <F2> :terminal <CR>
"use Ctrl-w-c to close the terminal
nnoremap <C-F3> :noh<CR>
nnoremap <F3> :call RunPythonInterp() <CR>
noremap <F4> :call CheckHeaderSource() <CR>
noremap <F6> :call TTakeInput() <CR>
noremap <F7> :call EnterNotes() <CR>
noremap <BS> 5k
noremap <Space> 5j
vnoremap . :norm.<CR>
nnoremap <C-Tab> gt
nnoremap <C-S-Tab> gT
nnoremap j gj
nnoremap k gk
nnoremap <leader>l :ls<CR>:b<space>
nnoremap <leader>bd :ls<CR>:bd<left><left>
nnoremap <left> :cp <CR>
nnoremap <right> :cn <CR>
nnoremap <C-t> :NERDTreeToggle .<CR>
noremap <C-F11> :NERDTreeFind <CR>
nnoremap <leader>ev :e $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
nmap <F8> :TagbarToggle<CR>
noremap <C-s> :w <CR>
imap <C-s> <Esc>:w<CR>VA
let g:ctrlp_working_path_mode = 'ra'
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.svn,
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
if executable('rg')
set grepprg=rg\ --color=never
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
endif
let g:ctrlp_extensions = ['tag', 'buffertag']
let g:ctrlp_root_markers = ['.svn']
set langmap=ёйцукенгшщзхъфывапролджэячсмитьбюЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ;`qwertyuiop[]asdfghjkl\\;'zxcvbnm\\,.~QWERTYUIOP{}ASDFGHJKL:\\"ZXCVBNM<>
set listchars=space:·,tab:→\
set list
highlight SpecialKey ctermfg=8 guifg=DimGrey
set ve=all
set belloff=all
nnoremap <leader>p :put = strftime('%H:%M')<CR>
noremap <Up> xi``<Esc>P
noremap <Down> dpBxx
hi my_bg_cursor guifg=#fabd2f guibg=#3c3836
hi! link CursorLineNr my_bg_cursor