-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
907 lines (720 loc) · 25.8 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
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" _____
" ___ ____(_)______ ___
" __ | / /_ /__ __ `__ \
" __ |/ /_ / _ / / / / /
" _____/ /_/ /_/ /_/ /_/
"
"
" Maintainer: Miroslav Bendík
" Version: 0.3
" -------------------------------------------------------------
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Basic settings
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" No compatible with vi
set nocompatible
" Enable vimrc
"set exrc
" Enable file type detection
filetype on
" Disable help
noremap <F1> ""
" Navigation with C-up / C-down
map <C-down> gj
map <C-up> gk
" Remap home
map <silent> <Home> ^
imap <silent> <Home> <C-O>^
" Long lines are on same indent level
set breakindent
" Enable history
set history=1000
" Enable : in keywords
set iskeyword=@,~,48-57,_,192-255
" Enable hidden buffers
set hidden
" Disable visual bell
set noerrorbells
set novisualbell
set t_vb=
" Set grep prorgram
set grepprg=grep\ -nH\ $*
" Set visible lines / columns before and after cursor
set scrolloff=3
set sidescroll=5
" Default text width to 80 chars
set textwidth=80
set colorcolumn=80
set wrap
" Mouse
set mouse=a
set mousehide
set mousemodel=popup
set mouseshape=n-v-ve-o-i-r:beam
set ttymouse=sgr
" Integrate clipboard
set clipboard=unnamed,unnamedplus
" Menu inside command line
set wildmenu
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Build
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Run make
map <F9> :make -j 2<CR>
" Auto jump to first error
set cf
let &errorformat="%-GIn file included from %f:%l:%c\\,,%-GIn file included from %f:%l:%c:,%-Gfrom %f:%l\\,,-Gfrom %f:%l:%c\\,," . &errorformat
set errorformat+=%D%*\\a[%*\\d]:\ Entering\ directory\ `%f'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Auto complete
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set completeopt=menuone,menu
" | |
" | + Display popup
" + Display when single option
" Hide help when cursor moved
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" Set cursor shape
let &t_SI = "\<Esc>[6 q"
let &t_EI = "\<Esc>[2 q"
if v:version > 704 || v:version == 704 && has('patch687')
let &t_SR = "\<Esc>[4 q"
end
" Complete shortcuts
imap <C-Space> <C-X><C-I>
imap <Nul> <C-X><C-I>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let s:plugins = {}
" Returns plugin settings
function s:getPluginSettings(name)
if ! has_key(s:plugins, a:name)
let s:plugins[a:name] = {'run_pre': [], 'run_post': []}
endif
return s:plugins[a:name]
endfunction
" Load plugin a reutnr pre / post init scripts
function s:loadPlugin(name)
let settings = s:getPluginSettings(a:name)
if has_key(settings, "loaded")
return
endif
let settings["loaded"] = 1
" Run pre scripts
for Fn in settings['run_pre']
call Fn()
endfor
" Load plugin
execute "packadd " . a:name
" Return post scripts
for Fn in settings['run_post']
call Fn()
endfor
endfunction
" Register pre script for plugin
function s:pluginPre(name, fn)
let settings = s:getPluginSettings(a:name)
call add(settings['run_pre'], a:fn)
endfunction
" Register post script for plugin
function s:pluginPost(name, fn)
let settings = s:getPluginSettings(a:name)
call add(settings['run_post'], a:fn)
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Individual plugins
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" YouCompleteMe
function s:init_YouCompleteMe()
let g:ycm_key_list_select_completion = ['<Down>']
let g:ycm_key_list_previous_completion = ['<Up>']
let g:ycm_confirm_extra_conf = 0
autocmd FileType python nmap <buffer> <F12> :YcmCompleter GoToDefinitionElseDeclaration<CR>
nmap <buffer> <F12> :YcmCompleter GoToDefinitionElseDeclaration<CR>
endfunction
call s:pluginPre("YouCompleteMe", function("s:init_YouCompleteMe"))
" ale
function s:init_ale()
let g:ale_lint_on_text_changed = "never"
let g:ale_lint_on_enter = 0
let g:ale_lint_on_filetype_changed = 0
let g:ale_lint_on_save = 1
let g:ale_lint_on_insert_leave = 0
let g:ale_java_javac_classpath = '/opt/android-sdk/platforms/android-31/android.jar'
endfunction
call s:pluginPre("ale", function("s:init_ale"))
" ctrlp
function s:init_ctrlp()
unmap <c-p>
"let g:ctrlp_use_caching = 0
let g:ctrlp_cache_dir = $HOME . '/.cache/ctrlp'
let g:ctrlp_follow_symlinks = 1
let g:ctrlp_working_path_mode = 'raw'
if executable('ag')
let g:ctrlp_user_command = 'ag %s --ignore-case --nogroup --nocolor --hidden --follow
\ -U -p ~/.ignore
\ -l -m 50000
\ -g ""'
endif
endfunction
function s:init_ctrlp_py_matcher()
let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
endfunction
function s:init_ctrlp_py_matcher_post()
:CtrlP
endfunction
call s:pluginPre("ctrlp", function("s:init_ctrlp"))
call s:pluginPre("ctrlp-py-matcher", function("s:init_ctrlp_py_matcher"))
call s:pluginPost("ctrlp-py-matcher", function("s:init_ctrlp_py_matcher_post"))
" gundo
function s:init_gundo()
nunmap <F7>
let g:gundo_prefer_python3=1
endfunction
function s:init_gundo_post()
nmap <F7> :GundoToggle<CR>
"call feedkeys("\<F7>")
:GundoToggle
endfunction
call s:pluginPre("gundo", function("s:init_gundo"))
call s:pluginPost("gundo", function("s:init_gundo_post"))
" powerline
set rtp+=$HOME/.vim/pack/plugins/start/powerline/powerline/bindings/vim
" python-mode
let g:pymode_options = 0
let g:pymode_rope = 1
let g:pymode_rope_completion = 0
let g:pymode_rope_complete_on_dot = 0
let g:pymode_rope_completion_bind = '<C-Shift-Space>'
let g:pymode_indent = 0
let g:pymode_syntax = 0
let g:pymode_lint = 0
let g:pymode_folding = 0
let g:pymode_rope_autoimport = 1
"let g:pymode_debug = 1
" ultisnips
function Ultisnips_get_current_python_class()
let l:retval = ""
let l:line_declaring_class = search('^class\s\+', 'bnW')
if l:line_declaring_class != 0
let l:nameline = getline(l:line_declaring_class)
let l:classend = matchend(l:nameline, '\s*class\s\+')
let l:classnameend = matchend(l:nameline, '\s*class\s\+[A-Za-z0-9_]\+')
let l:retval = strpart(l:nameline, l:classend, l:classnameend-l:classend)
endif
return l:retval
endfunction
function Ultisnips_get_current_python_method()
let l:retval = ""
let l:line_declaring_method = search('\s*def\s\+', 'bnW')
if l:line_declaring_method != 0
let l:nameline = getline(l:line_declaring_method)
let l:methodend = matchend(l:nameline, '\s*def\s\+')
let l:methodnameend = matchend(l:nameline, '\s*def\s\+[A-Za-z0-9_]\+')
let l:retval = strpart(l:nameline, l:methodend, l:methodnameend-l:methodend)
endif
return l:retval
endfunction
function s:init_ultisnips()
let g:UltiSnipsExpandTrigger="<TAB>"
let g:UltiSnipsJumpForwardTrigger="<TAB>"
let g:UltiSnipsSnippetDirectories = ['.vim/UltiSnips', 'UltiSnips']
let g:UltiSnipsTriggerInVisualMode=0
endfunction
call s:pluginPre("ultisnips", function("s:init_ultisnips"))
" bufferlist
"
function s:init_bufferlist()
unmap <F3>
endfunction
function s:init_bufferlist_post()
map <silent> <F3> :call BufferList()<CR>
call BufferList()
endfunction
call s:pluginPre("vim-bufferlist", function("s:init_bufferlist"))
call s:pluginPost("vim-bufferlist", function("s:init_bufferlist_post"))
" tagbar
function s:init_tagbar()
nunmap <F11>
endfunction
function s:init_tagbar_post()
nmap <F11> :TagbarToggle<CR>
:TagbarToggle
endfunction
call s:pluginPre("tagbar", function("s:init_tagbar"))
call s:pluginPost("tagbar", function("s:init_tagbar_post"))
" indent-guides
let g:indent_guides_auto_colors = 0
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_exclude_filetypes = ['help', 'nerdtree', 'project']
let g:indent_guides_space_guides = 0
let g:indent_guides_start_level = 1
let g:indent_guides_indent_levels = 10
" signify
function s:init_signify_post()
:SignifyEnable
endfunction
call s:pluginPost("signify", function("s:init_signify_post"))
" jsavascript
function s:init_javascript()
let g:javascript_conceal = 1
let g:javascript_conceal_function = "∫"
let g:javascript_conceal_null = "Ø"
let g:javascript_conceal_this = "@"
let g:javascript_conceal_return = "❱"
let g:javascript_conceal_undefined = "¿"
let g:javascript_conceal_NaN = "Ṉ"
let g:javascript_conceal_prototype = "¶"
let g:javascript_conceal_static = "•"
let g:javascript_conceal_super = "Ω"
endfunction
call s:pluginPre("vim-javascript", function("s:init_javascript"))
"call s:loadPlugin("ultisnips")
"call s:loadPlugin("vim-snippets")
autocmd InsertEnter * ++once call s:loadPlugin("ultisnips")
autocmd InsertEnter * ++once call s:loadPlugin("vim-snippets")
autocmd InsertEnter * ++once call s:loadPlugin("YouCompleteMe")
nmap <F12> :call <SID>loadPlugin("YouCompleteMe")<CR>:YcmCompleter GoToDefinitionElseDeclaration<CR>
autocmd FileType javascript,python,java ++once call s:loadPlugin("ale")
autocmd FileType python ++once call s:loadPlugin("killor")
map <c-p> :call <SID>loadPlugin("ctrlp")<CR>:call <SID>loadPlugin("ctrlp-py-matcher")<CR>
autocmd InsertEnter * ++once call s:loadPlugin("delimitMate")
autocmd FileType html,htmldjango ++once call s:loadPlugin("emmet-vim")
nmap <F7> :call <SID>loadPlugin("gundo")<CR>
autocmd InsertEnter * ++once call s:loadPlugin("nerdcommenter")
map <F3> :call <SID>loadPlugin("vim-bufferlist")<CR>
nmap <F11> :call <SID>loadPlugin("tagbar")<CR>
autocmd FileType css,scss ++once call s:loadPlugin("vim-css3-syntax")
autocmd InsertEnter * ++once call s:loadPlugin("vim-signify")
autocmd FileType javascript ++once call s:loadPlugin("vim-javascript")
autocmd FileType po ++once call s:loadPlugin("po")
autocmd FileType glsl ++once call s:loadPlugin("vim-glsl")
filetype indent on
filetype plugin on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Saving
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Write after buffer leave
" set autowrite
" Backup
set backup
set backupdir=~/.vim/backup//,.,~/
" Tmp directory
set directory=~/.vim/tmp//,~/tmp,.,/tmp
" Ask before close
set confirm
" Viminfo
set viminfo='50,\"500
" | |
" | + Maximum number of files for each register
" + Save max 50 files
" Persistend undo
set undodir=~/.vim/undodir//
set undofile
set undolevels=2048
set undoreload=65538
" Reload file, preserve history
command! Reload %d|r|1d
" Save with ctrl+s
map <C-S> :w<CR>
imap <C-S> <ESC><C-S>
" HTML
let html_number_lines = 0
let use_xhtml = 1
let html_use_css = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Formating
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set formatoptions=croq1
" |||||
" ||||+ Not break lines in insert mode
" |||+ Formatting with gq
" ||+ Insert comment leader after 'o'
" |+ Insert comment leader after <Enter>
" + Auto wrap comments using textwidth
" Wrap on end
set wrapmargin=0
set linebreak
" Copy indent structure
set copyindent
set preserveindent
" Round to tabs
set shiftround
" Use tabs
set tabstop=3
set shiftwidth=3
" Indent for language
set smartindent
set display=lastline
" Adjust indent
xnoremap <Tab> >gv
au BufEnter * xnoremap <Tab> >gv
au InsertLeave * xnoremap <Tab> >gv
xmap <BS> <gv
command! RetabIndents call RetabIndents()
command! Python2Completer :YcmCompleter RestartServer /usr/bin/python2
command! Python3Completer :YcmCompleter RestartServer /usr/bin/python3
func! RetabIndents()
execute '%!unexpand --first-only -t '.&ts
endfunc
func! ReformatHTML() range
let content = join(getline(a:firstline, a:lastline), "\n")
let baka = @a
let baks = @/
let @a = content
silent execute 'new'
silent execute 'normal "ap'
silent execute 'set filetype=html'
silent execute ':%s/^\s*//g'
silent execute ':%s/\s*$//g'
silent execute ':%s/<[^>]*>/\r&\r/g'
silent execute ':%g/^$/d'
silent execute 'normal 1G'
silent execute 'normal VG'
silent execute 'normal ='
silent execute 'normal 1G'
silent execute 'normal VG'
silent execute 'normal "ay'
silent execute ':bdelete!'
silent execute a:firstline.','.a:lastline.'d'
silent execute 'normal "aP'
let @a = baka
let @/ = baks
endfunc
command! -range=% ReformatHTML <line1>,<line2>call ReformatHTML()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Snippets
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
imap \... …
" Better completion for {
inoremap {<CR> {<CR><C-D>}<Esc>O
" Disable delimitmate for file types
let delimitMate_excluded_ft = "mail,txt,htmldjango"
" Wrap
vmap ( <ESC>`>a)<ESC>`<i((<ESC>gv
vmap [ <ESC>`>a]<ESC>`<i[[<ESC>gv
vmap { <ESC>`>a}<ESC>`<i{{<ESC>gv
vmap \' <ESC>`>a''<ESC>`<i''<ESC>gv
vmap \" <ESC>`>a""<ESC>`<i""<ESC>gv
vmap ; <ESC>`>a“<ESC>`<i„<ESC>gv
" Reverse chars
vmap \rv c<C-O>:set revins<CR><C-R>"<Esc>:set norevins<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Display
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable line number display
set number
" Hide conceal chars
set conceallevel=2
" Enable statusline
set laststatus=2
" Show title in terminal window
set title
" Show matching brackets
set showmatch
" Highlidhgt search
set hlsearch
set incsearch
" Disable toolbars
if has("gui_running")
set guioptions-=T
endif
" Enable syntax
syntax on
" Fast tty (no optimization)
set ttyfast
" Fast regexp engine
"set regexpengine=1
" Automatic sync (slow!)
" autocmd BufEnter * syntax sync fromstart
" Max 500 lines for syntax
" syntax sync minlines=500
" Colorscheme
if (&t_Co == 256) || has("gui_running")
colorscheme mirec
else
colorscheme default
endif
" Split symbols
if has("multi_byte")
set fillchars=stl:\ ,stlnc:\ ,vert:┆,fold:-,diff:-
else
set fillchars=stl:\ ,stlnc:\ ,vert:\|,fold:-,diff:-
endif
" Whitespace symbols
if has("multi_byte")
"set lcs=tab:\⁝\ ,trail:•,extends:>,precedes:<,nbsp:¤"
set lcs=tab:\┆\ ,trail:•,extends:>,precedes:<,nbsp:¤"
let &sbr = nr2char(8618).' '
else
set lcs=tab:>\ ,extends:>,precedes:<,trail:-
let &sbr = '+++ '
endif
function! UpdateLcs()
if (&previewwindow)
setlocal nolist
endif
if (bufname('%') == "__BUFFERLIST__")
setlocal nolist
endif
endfunction
autocmd BufEnter,BufWinEnter,WinEnter,CmdwinEnter * call UpdateLcs()
set list
" Highlight extra whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
autocmd BufWinEnter *{cpp,h,hpp,php,python,css,js,html,xhtml,htm} match ExtraWhitespace /\s\+$\| \+\ze\t/
autocmd InsertEnter *{cpp,h,hpp,php,python,css,js,html,xhtml,htm} match ExtraWhitespace /\s\+\%#\@<!$\| \+\ze\t\%#\@<!/
autocmd InsertLeave *{cpp,h,hpp,php,python,css,js,html,xhtml,htm} match ExtraWhitespace /\s\+$\| \+\ze\t/
autocmd BufWinLeave *{cpp,h,hpp,php,python,css,js,html,xhtml,htm} call clearmatches()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Settings for file types
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" cpp
function! EnhanceCppSyntax()
syn match cppFuncDef "::\~\?\zs\h\w*\ze([^)]*\()\s*\(const\)\?\)\?$"
endfunction
autocmd Syntax cpp call EnhanceCppSyntax()
autocmd FileType c,cpp nmap <F5> "lYml[[kw"cye'l
autocmd FileType c,cpp nmap <F6> :set paste<CR>ma:let @n=@/<CR>"lp==:s/\<virtual\>\s*//e<CR>:s/\<static\>\s*//e<CR>:s/\<explicit\>\s*//e<CR>:s/\s*=\s*[^,)]*//ge<CR>:let @/=@n<CR>'ajf(b"cPa::<Esc>f;s<CR>{<CR>}<CR><Esc>kk:nohlsearch<CR>:set nopaste<CR>
autocmd FileType c,cpp set foldmethod=indent
autocmd FileType c,cpp set foldlevel=6
" python
autocmd BufNewFile *.py execute "set paste" | execute "normal i# -*- coding: utf-8 -*-\r" | execute "set nopaste"
autocmd FileType python set completeopt=menuone,menu,preview
autocmd FileType python setlocal complete+=k
autocmd FileType python setlocal isk+=".,("
autocmd BufRead *.py setlocal makeprg=python\ -c\ \"import\ py_compile,sys;\ sys.stderr=sys.stdout;\ py_compile.compile(r'%')\"
autocmd BufRead *.py setlocal efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
"autocmd BufRead *.py let g:pymode_rope_project_root = finddir('.ropeproject', expand("<afile>"))
"autocmd BufReadPre *.py let g:pymode_rope_project_root=finddir('.ropeproject', expand("<afile>"))
"autocmd BufReadPre,BufNewFile *.py let f=expand("%:p:h") . ";" | let rope_dir=finddir(".ropeproject", f) | if rope_dir == "" || rope_dir == expand("$HOME/.ropeproject") | let g:pymode_rope_project_root="" | else | let rope_absdir=fnamemodify(rope_dir, ':p:h:h') | let g:pymode_rope_project_root=rope_absdir | endif
autocmd BufReadPre,BufNewFile,BufEnter *.py if exists('b:pymode_rope_project_root') | let g:pymode_rope_project_root=b:pymode_rope_project_root | else | let f=expand("%:p:h") . ";" | let rope_dir=finddir(".ropeproject", f) | if rope_dir == "" || rope_dir == expand("$HOME/.ropeproject") | let b:pymode_rope_project_root="" | else | let rope_absdir=fnamemodify(rope_dir, ':p:h:h') | let b:pymode_rope_project_root=rope_absdir | endif | let g:pymode_rope_project_root=b:pymode_rope_project_root | endif
au BufNewFile,BufRead *.jinja set ft=htmldjango
au BufNewFile,BufRead *.vert,*.tesc,*.tese,*.glsl,*.geom,*.frag,*.comp set filetype=glsl
" Disable indentkeys
set indentkeys-=<:>
let g:python_recommended_style=0
let g:pyindent_open_paren = shiftwidth()
let g:pyindent_continue = shiftwidth()
let g:pyindent_close_paren = -shiftwidth()
let g:rst_style=0
" javascript
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType javascript set completefunc=javascriptcomplete#CompleteJS
" html
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType html set completefunc=htmlcomplete#CompleteTags
autocmd FileType html set filetype=htmldjango
autocmd FileType htmldjango vmap \tr <ESC>`>a'' %}<ESC>`<i{{% trans ''<ESC>
autocmd FileType htmldjango vmap \tj <ESC>:set paste<CR>`>a{% endtrans %}<ESC>`<i{% trans %}<ESC>`>:set nopaste<CR>
" css
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType css set completefunc=csscomplete#CompleteCSS
" common completion
autocmd FileType c,cpp,java,php,python,html,css,javascript imap <C-Space> <C-X><C-O>
autocmd FileType c,cpp,java,php,python,html,css,javascript imap <Nul> <C-X><C-O>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Utility
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Convert vimrc to HTML
" Link to section: *> Section name
" Section: => Section name
function! VimrcTOHtml()
TOhtml
try
silent exe '%s/"\(\s\+\)\*> \(.\+\)</"\1<a href="#\2" style="color: #bdf">\2<\/a></g'
catch
endtry
try
silent exe '%s/"\(\s\+\)=> \(.\+\)</"\1<a name="\2" style="color: #fff">\2<\/a></g'
catch
endtry
exe ":write!"
exe ":bd"
endfunction
function! ReformatXml()
%!xmllint --format --recover --encode utf-8 - 2>/dev/null
endfunction
command! ReformatXml call ReformatXml()
function! ReplaceDiacritic()
execute "silent! " . a:firstline . "," . a:lastline . "s/Ľ/\\Ľ/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Š/\\Š/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ť/\\Ť/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ž/\\Ž/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ľ/\\ľ/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/š/\\š/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ť/\\ť/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ž/\\ž/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ŕ/\\Ŕ/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ĺ/\\Ĺ/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Č/\\Č/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ě/\\Ě/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ď/\\Ď/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ň/\\Ň/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ř/\\Ř/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ů/\\Ů/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ŕ/\\ŕ/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ľ/\\ĺ/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/č/\\č/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ě/\\ě/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ď/\\ď/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ň/\\ň/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ř/\\ř/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ô/\\ô/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ô/\\Ô/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ý/\\Ý/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ý/\\ý/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Á/\\Á/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/á/\\á/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/É/\\É/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/é/\\é/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Í/\\Í/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/í/\\í/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ó/\\Ó/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ó/\\ó/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/Ú/\\Ú/g"
execute "silent! " . a:firstline . "," . a:lastline . "s/ú/\\ú/g"
endfunction
function! MailSettings()
setlocal textwidth=0
setlocal comments+=b:--
setlocal formatoptions+=tcqan
" setlocal nosi nocin
" setlocal comments=n:>
" setlocal equalprg=fmt
" Odstránenie starých podpisov
" autocmd BufReadPost /tmp/mutt* :g/^> -- $/.;/^$/-d
try | :%s/>> -- $\n\(>> .*\n\)*// | catch | endtry
try | :%s/> -- $\n\(> .*\n\)*// | catch | endtry
" Zmena zlého formátu citácií
try | :%s/^> >/>> / | catch | endtry
try | :%s/^>> >/>>> / | catch | endtry
try | :%s/^>>> >/>>>> / | catch | endtry
" Odstránenie prebytočných riadkov
try | %s/\(^>\n\)\{2,}/>\r/g | catch | endtry
" Presun nad pätičku
normal 0G
normal 8k
setlocal ignorecase infercase
"setlocal wrap
setlocal nocp
let @/ = '^>[ \t]*$'
let b:url_nr = 1
vmap <buffer> . c> [[...]<Esc>
" insert mode mappings
imap <buffer> <C-l> <ESC>:call MailInsertURL()<CR>
"map <buffer> <F2> :%g/^>\( \?>\)/d<CR>
"map <buffer> <F3> :%g/^>\( \?>\)\{2}/d<CR>
"map <buffer> <F4> :%g/^>\( \?>\)\{3}/d<CR>
map <buffer> <leader>q :%s/=\(\x\x\)/\=nr2char(str2nr(submatch(1),16))/g<CR>
function! MailInsertURL()
set paste
let l:url = input("URL: ")
execute "normal a[".b:url_nr."]\<Esc>mzG"
try
execute "?^-- $"
if b:url_nr == 1
normal 0k
else
normal k
endif
catch
endtry
execute "normal o[".b:url_nr."] ".l:url."\<Esc>`za"
let b:url_nr += 1
set nopaste
endfunction
endfunction
au BufReadPost * if getfsize(bufname("%")) > 512*1024 | set syntax= | endif
"au Syntax * RainbowParenthesesLoadRound
"au Syntax * RainbowParenthesesLoadSquare
"au Syntax * RainbowParenthesesLoadBraces
"let g:rbpt_colorpairs = [
" \ ['brown', 'RoyalBlue3'],
" \ ['Darkblue', 'SeaGreen3'],
" \ ['darkgray', 'DarkOrchid3'],
" \ ['darkgreen', 'firebrick3'],
" \ ['darkcyan', 'RoyalBlue3'],
" \ ['darkred', 'SeaGreen3'],
" \ ['darkmagenta', 'DarkOrchid3'],
" \ ['brown', 'firebrick3'],
" \ ['gray', 'RoyalBlue3'],
" \ ['196', '#ff0000'],
" \ ['200', '#ff00df'],
" \ ['39', '#00afff'],
" \ ['87', '#5fffff'],
" \ ['118', '#87ff00'],
" \ ['229', '#ffffaf'],
" \ ['255', '#eeeeee'],
" \ ]
function! CleanCSS()
try
silent execute "%s/\\t\\+$//g"
catch
endtry
try
silent execute "%s/[ ]\\+$//g"
catch
endtry
try
silent execute "%s/\\([^ ]\\){/\\1 {/g"
catch
endtry
try
silent execute "%s/:\\([^ ]\\)\\(.*\\);/: \\1\\2;/"
catch
endtry
endfunction
function! WriteCreatingDirs()
execute 'normal !mkdir -p %:h'
execute 'normal write'
endfunction
command W call WriteCreatingDirs()
let c_no_curly_error = 1
function s:MkNonExDir(file, buf)
if empty(getbufvar(a:buf, '&buftype')) && a:file!~#'\v^\w+\:\/'
let dir=fnamemodify(a:file, ':h')
if !isdirectory(dir)
call mkdir(dir, 'p')
endif
endif
endfunction
augroup BWCCreateDir
autocmd!
autocmd BufWritePre * :call s:MkNonExDir(expand('<afile>'), +expand('<abuf>'))
augroup END
" Protect large files from sourcing and other overhead.
" Files become read only
if !exists("my_auto_commands_loaded")
let my_auto_commands_loaded = 1
" Large files are > 10M
" Set options:
" eventignore+=FileType (no syntax highlighting etc
" assumes FileType always on)
" noswapfile (save copy of file)
" bufhidden=unload (save memory when other file is viewed)
" buftype=nowrite (file is read-only)
" undolevels=-1 (no undo possible)
let g:LargeFile = 1024 * 1024
augroup LargeFile
autocmd BufReadPre * let f=expand("<afile>") | if getfsize(f) > g:LargeFile | set eventignore+=FileType | setlocal noswapfile bufhidden=unload buftype=nowrite undolevels=-1 | else | set eventignore-=FileType | endif
augroup END
endif
function! HTMLTextHighlight()
syntax off
syntax region comment start=/</ end=/>/
syntax region comment start=/</ end=/>/
syntax region comment start=/{%/ end=/%}/
syntax region comment start=/{{/ end=/}}/
syntax region comment start=/{#/ end=/#}/
syntax match Title /{%\s*\(end\)\?trans[^%]*%}/
endfunction
function! ChangeTimetrackPrompt()
let git_dir=system("cd -- ".expand("%:p:h::S")." && git rev-parse --absolute-git-dir")->split('\n', 1)[0]
endfunction
map <buffer> <leader>gh :0GlLog<CR>
" :cexpr system('find . -name whatever.txt -printf "%p:1:1:%f\n"')