-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.vimrc
More file actions
1247 lines (1041 loc) · 31.1 KB
/
Copy path.vimrc
File metadata and controls
1247 lines (1041 loc) · 31.1 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
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
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" Notes {
" vim: set nofoldenable foldmethod=marker foldmarker={,} foldlevel=0:
"
" _
" _ __ ___ ___ _ __ | | _____ _ _ __ _(_)_ __ ___
" | '_ ` _ \ / _ \| '_ \| |/ / _ \ | | |____\ \ / / | '_ ` _ \
" | | | | | | (_) | | | | < __/ |_| |_____\ V /| | | | | | |
" |_| |_| |_|\___/|_| |_|_|\_\___|\__, | \_/ |_|_| |_| |_|
" |___/
"
" Author: Charles Qiu
" Email: Thinking.QMonkey@GMail.com
" }
" Init {
" Install vim-plug if not present
if empty(glob($HOME . '/.vim/autoload/plug.vim'))
let s:path = expand('/.vim/autoload/plug.vim')
silent execute '!curl' '-fLo' $HOME . s:path '--create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
augroup Init
autocmd!
autocmd VimEnter * PlugInstall | source $MYVIMRC
autocmd VimEnter * call mkdir($HOME . '/.vim/swap/', 'p') | call InitClangFormat()
augroup END
endif
function! InitClangFormat()
let l:lines = [
\ 'BasedOnStyle: LLVM',
\ 'IndentWidth: 8',
\ 'UseTab: Always',
\ 'BreakBeforeBraces: Linux',
\ 'AllowShortIfStatementsOnASingleLine: false',
\ 'IndentCaseLabels: false'
\ ]
call writefile(l:lines, $HOME . '/.clang-format')
endfunction
" }
" vim-plug {
" Time limit of each task in seconds
let g:plug_timeout = 300
" }
call plug#begin(expand($HOME . '/.vim/bundle'))
" Plugins {
Plug 'tomasr/molokai'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'itchyny/lightline.vim'
Plug 'Yggdroot/LeaderF', {'do': ':LeaderfInstallCExtension'}
Plug 'dyng/ctrlsf.vim'
Plug 'mg979/vim-visual-multi'
Plug 'justinmk/vim-dirvish'
Plug 'tpope/vim-obsession'
Plug 'monkoose/vim9-stargate'
Plug 'wellle/targets.vim'
Plug 'michaeljsmith/vim-indent-object'
Plug 'svermeulen/vim-subversive'
Plug 'Konfekt/FastFold'
Plug 'haya14busa/vim-asterisk'
Plug 'dominikduda/vim_current_word'
Plug 'ntpeters/vim-better-whitespace'
Plug 'skywind3000/asyncrun.vim'
Plug 'airblade/vim-rooter'
Plug 'ludovicchabant/vim-gutentags'
Plug 'yegappan/lsp'
Plug 'hrsh7th/vim-vsnip' | Plug 'hrsh7th/vim-vsnip-integ' | Plug 'rafamadriz/friendly-snippets'
Plug 'tpope/vim-fugitive' | Plug 'junegunn/gv.vim', {'on': 'GV'}
Plug 'Eliot00/git-lens.vim'
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'jiangmiao/auto-pairs'
Plug 'andymass/vim-matchup'
Plug 'kshenoy/vim-signature'
Plug 'tpope/vim-eunuch'
Plug 'romainl/vim-qf'
Plug 'shime/vim-livedown', {'for': 'markdown', 'on': 'LivedownPreview'}
" }
" Add plugins to &runtimepath
call plug#end()
" Builtin packages {
silent! packadd! comment
silent! packadd! hlyank
silent! packadd! nohlsearch
" Enable 'Man' command
source $VIMRUNTIME/ftplugin/man.vim
" Disable netrw
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
" }
" Leader {
let g:mapleader = ','
" }
" Encoding {
language message en_US.UTF-8
set langmenu=en_US.UTF-8
set encoding=utf-8
scriptencoding utf-8
" Only work in terminal vim
set termencoding=utf-8
set fileencodings=utf-8,gb18030,cp936,ucs-bom,big5,euc-jp,euc-kr,latin1
" }
" Number {
set relativenumber number
augroup RelativeNumber
autocmd!
" Only display relativenumber in active normal mode buffer
autocmd WinEnter,BufEnter,InsertLeave * set relativenumber
autocmd WinLeave,BufLeave,InsertEnter * set norelativenumber number
augroup END
" }
" Show the cursor position all the time
set ruler
set showmatch
" Cursorline {
" Highlight current line
set cursorline
augroup CursorLine
autocmd!
" Disable cursorline in insert mode
autocmd InsertEnter * set nocursorline
autocmd InsertLeave * set cursorline
augroup END
" }
" Search in time
set incsearch
set hlsearch
set ignorecase
set smartcase
" Show search count message when searching
set shortmess-=S shortmess+=s
" The ":substitute" flag 'g' is default on. This means that
" all matches in a line are substituted instead of one. When a 'g' flag
" is given to a ":substitute" command, this will toggle the substitution
" of all or one match
set gdefault
set wildmenu
set wildmode=list:longest,full
" Complete options (disable preview scratch window, longest removed to aways show menu)
set completeopt=menu,menuone
" For regular expressions turn magic on, and you don't need to add '\' before some special meaning characters.
set magic
" Swap file directory
set directory=$HOME/.vim/swap//
" Make the jumplist behave like the tagstack
set jumpoptions+=stack
" Share vim clipboard with system clipboard (gvim -v in xterm)
if has('unnamedplus')
" When possible use + register for copy-paste
set clipboard=unnamed,unnamedplus
else
" On Mac and Windows, use * register for copy-paste
set clipboard=unnamed
endif
set smartindent
" Indent at the same level of the previous line
set autoindent
" Make "tab" insert indents instead of tabs at the beginning of a line
set smarttab
" Size of a hard tabstop
set tabstop=8
set softtabstop=8
" Size of an "indent"
set shiftwidth=8
" Never use space to replace tab
set noexpandtab
set textwidth=0
set wrap
set breakindent
set splitright
" For mappings
set timeout
set timeoutlen=1000
" For key codes
set ttimeout
" Unnoticeable small value
set ttimeoutlen=10
" Show tab, eof and trail space
set list
set listchars=tab:▸\ ,eol:¬,trail:·
" Restore cursor to previous editing position
augroup RestoreCursorPosition
autocmd!
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | execute "normal! g'\"" | endif
augroup END
" Clear jumplist on vim startup
augroup Jumplist
autocmd!
autocmd VimEnter * :clearjumps
augroup END
" FileType {
augroup FileTypeGroup
autocmd!
autocmd FileType python,markdown setlocal expandtab tabstop=4 shiftwidth=4 softtabstop=4
autocmd FileType json setlocal expandtab tabstop=2 shiftwidth=2 softtabstop=2
autocmd BufNewFile *.sh,*.py call AutoInsertFileHead()
" Move the quickfix window to the bottom of the window layout
autocmd FileType qf wincmd J
augroup END
function! AutoInsertFileHead()
" Shell
if &filetype ==# 'sh'
call setline(1, '#!/bin/bash')
endif
" Python
if &filetype ==# 'python'
call setline(1, '#!/usr/bin/env python3')
call setline(2, '# -*- coding: utf-8 -*-')
endif
call cursor(line('$'), 0)
put = repeat(nr2char(10), 2)
call cursor(line('$'), 0)
endfunc
" }
" Docset {
augroup Docset
autocmd!
autocmd FileType man,help setlocal nolist
" Use :LspHover as the default docset
autocmd FileType * setlocal keywordprg=:LspHover
autocmd FileType c,man setlocal keywordprg=:Man
autocmd FileType vim,help setlocal keywordprg=:help
augroup END
" }
" Resize splits when the window is resized
function! ResizeAllTab()
let l:cur_tab = tabpagenr()
silent! execute 'tabdo wincmd ='
silent! execute 'tabnext ' . l:cur_tab
endfunction
augroup AutoResize
autocmd!
autocmd VimResized * call ResizeAllTab()
augroup END
" Number of lines from vertical edge to start scrolling
set scrolloff=7
" Number of cols from horizontal edge to start scrolling
set sidescrolloff=15
" Number of cols to scroll at a time
set sidescroll=1
" Disable fold on startup
set nofoldenable
set foldmethod=syntax
set foldlevel=99
" Use indent style fold for python
augroup PythonFold
autocmd!
autocmd FileType python setlocal foldmethod=indent
augroup END
" Character width. Should never be enable!
"set ambiwidth=double
" Use both Unix, DOS and Mac file formats, but favor the Unix one for new files
set fileformats=unix,dos,mac
" Configure backspace so it acts as it should act
set backspace=indent,eol,start
" Allow switching away from a changed buffer without saving
set hidden
" Auto reload file changes outside vim
set autoread
" No bells
set belloff=all
" Enable mouse in normal, visual and insert mode
set mouse=nvi
" Only if there are at least two tab pages
set showtabline=1
" Always show status line
set laststatus=2
" lightline.vim {
let g:lightline = {
\ 'colorscheme': 'powerline',
\ 'active': {
\ 'left': [['mode', 'paste'], ['gitgutter', 'fugitive', 'filename']],
\ 'right': [['linter_ok', 'linter_warnings', 'linter_errors', 'linter_checking', 'lineinfo'], ['percent'], ['filetype', 'fileencoding', 'fileformat']]
\ },
\ 'inactive': {
\ 'left': [['mode', 'filename']],
\ 'right': []
\ },
\ 'component_function': {
\ 'gitgutter': 'LightLineGitGutter',
\ 'fugitive': 'LightLineFugitive',
\ 'filename': 'LightLineFilename',
\ 'fileformat': 'LightLineFileformat',
\ 'filetype': 'LightLineFiletype',
\ 'fileencoding': 'LightLineFileencoding',
\ 'percent': 'LightLinePercent',
\ 'lineinfo': 'LightLineLineInfo',
\ 'mode': 'LightLineMode',
\ },
\ 'component_expand': {
\ 'tabs': 'lightline#tabs',
\ },
\ 'component_type': {
\ 'linter_checking': 'left',
\ 'linter_errors': 'error',
\ 'linter_warnings': 'warning',
\ 'linter_ok': 'left',
\ },
\ 'separator': {'left': '', 'right': ''},
\ 'subseparator': {'left': '│', 'right': '│'},
\ 'tab': {
\ 'active': ['filename', 'modified'],
\ 'inactive': ['filename', 'modified'],
\ },
\ 'tabline': {
\ 'left': [['tabs']],
\ 'right': []
\ },
\ 'tabline_separator': {'left': '', 'right': ''},
\ 'tabline_subseparator': {'left': '│', 'right': '│'},
\ }
function! LightLineModified()
return &filetype =~# 'help' ? '' : &modified ? '+' : &modifiable ? '' : '-'
endfunction
function! LightLineReadonly()
return &filetype !~? 'help' && &readonly ? '🔒' : ''
endfunction
function! LightLineFilename()
if GetWindowType() != 0
return ''
endif
let l:fname = expand('%:t')
return ('' !=# LightLineReadonly() ? LightLineReadonly() . ' ' : '') .
\ ('' !=# l:fname ? l:fname : '[No Name]') .
\ ('' !=# LightLineModified() ? ' ' . LightLineModified() : '')
endfunction
function! GetWindowType()
if &previewwindow
return 3
endif
if &filetype is# 'qf'
let l:cur_winnr = winnr()
if qf#IsQfWindow(l:cur_winnr)
return 2
elseif qf#IsLocWindow(l:cur_winnr)
return 1
endif
endif
return 0
endfunction
function! IsGitFile()
if !exists('g:loaded_gitgutter') || !exists('g:loaded_fugitive')
return 0
endif
let l:fname = expand('%:t')
let l:plugins = ['\[Plugins\]']
if l:fname ==# ''
return 0
endif
for l:plugin in l:plugins
if l:fname =~# l:plugin
return 0
endif
endfor
let l:git_dir = FugitiveExtractGitDir(resolve(expand('%')))
if l:git_dir ==# ''
return 0
endif
return 1
endfunction
function! LightLineGitGutter()
if GetWindowType() != 0
return ''
endif
if !IsGitFile()
return ''
endif
let l:summary = GitGutterGetHunkSummary()
return printf('+%d ~%d -%d', l:summary[0], l:summary[1], l:summary[2])
endfunction
function! LightLineFugitive()
if GetWindowType() != 0
return ''
endif
if !IsGitFile()
return ''
endif
try
if getftype(expand('%')) ==# 'link'
call FugitiveDetect(resolve(expand('%')))
endif
let l:mark = "\ue0a0 "
let l:branch = FugitiveHead()
return l:branch !=# '' ? l:mark.branch : ''
catch
endtry
return ''
endfunction
function! LightLineFileformat()
return winwidth(0) > 70 ? &fileformat : ''
endfunction
function! LightLineFiletype()
return winwidth(0) > 70 ? (&filetype !=# '' ? &filetype : 'unknown') : ''
endfunction
function! LightLineFileencoding()
return winwidth(0) > 70 ? (&fileencoding !=# '' ? &fileencoding : &encoding) : ''
endfunction
function! LightLinePercent()
return winwidth(0) > 70 ? printf('%3d%%', (100 * line('.') / line('$'))) : ''
endfunction
function! LightLineLineInfo()
return winwidth(0) > 70 ? printf('%3d/%-d :%-2d', line('.'), line('$'), col('.')) : ''
endfunction
function! LightLineMode()
let l:fname = expand('%:t')
let l:window_type = GetWindowType()
if l:window_type != 0
return l:window_type == 3 ? 'Preview' :
\ l:window_type == 2 ? 'Quickfix' :
\ l:window_type == 1 ? 'Location' : ''
endif
return winwidth(0) > 60 ? lightline#mode() : ''
endfunction
" }
" Enable 256 color for vim
set t_Co=256
" Inspired by http://sunaku.github.io/vim-256color-bce.html
if &term =~# '256color'
" Disable Background Color Erase (BCE) so that color schemes
" render properly when inside 256-color tmux and GNU screen.
" See also http://snk.tuxfamily.org/log/vim-256color-bce.html
set t_ut=
endif
" molokai {
" Should before colorscheme, do it by vim-plug
" syntax on
" Should before colorscheme, too
let g:molokai_original = 1
let g:rehash256 = 1
set background=dark
colorscheme molokai
" }
" vim-indent-guides {
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_start_level = 2
let g:indent_guides_guide_size = 1
let g:indent_guides_tab_guides = 0
let g:indent_guides_exclude_filetypes = ['diff', 'man', 'help', 'git', 'gitcommit', 'qf']
" }
" Key map {
" Make Y behave like other capitals
nnoremap Y y$
" Improve up/down movement on wrapped lines
noremap j gj
noremap k gk
" Jump to start and end of line using the home row keys
noremap H ^
noremap L $
" Keep text selected after manual indentation
vnoremap < <gv
vnoremap > >gv
noremap ; :
" Remap U to <C-r> for easier redo
nnoremap U <C-r>
" Better insert mode moving and editing
inoremap <C-p> <Up>
inoremap <C-n> <Down>
inoremap <C-b> <Left>
inoremap <C-f> <Right>
inoremap <C-a> <Home>
inoremap <C-e> <End>
inoremap <C-h> <BackSpace>
inoremap <C-d> <Del>
" Better command mode moving and editing
cnoremap <C-p> <Up>
cnoremap <C-n> <Down>
cnoremap <C-b> <Left>
cnoremap <C-f> <Right>
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
cnoremap <C-h> <BackSpace>
cnoremap <C-d> <Del>
nnoremap <silent>q :call Quit()<CR>
nnoremap <silent><S-q> :quitall<CR>
noremap t q
function! Quit()
let l:last_winnr = winnr('#')
let l:window_type = GetWindowType()
quit
if l:window_type == 1 || l:window_type == 2
silent! execute l:last_winnr . 'wincmd w'
endif
endfunction
" }
" Buffer {
nnoremap <silent><Leader>o :execute 'edit' Prompt('New buffer name: ', '', 'file')<CR>
nnoremap <silent>[b :bprevious<CR>
nnoremap <silent>]b :bnext<CR>
" }
" Tab {
nnoremap <silent><Leader>t :execute 'tabnew' PathPrompt('New tab name: ', '', 'file')<CR>
nnoremap <silent>[t :tabprevious<CR>
nnoremap <silent>]t :tabnext<CR>
nnoremap <Leader>1 1gt
nnoremap <Leader>2 2gt
nnoremap <Leader>3 3gt
nnoremap <Leader>4 4gt
nnoremap <Leader>5 5gt
nnoremap <Leader>6 6gt
nnoremap <Leader>7 7gt
nnoremap <Leader>8 8gt
nnoremap <Leader>9 9gt
nnoremap <Leader>[ :tabfirst<CR>
nnoremap <Leader>] :tablast<CR>
" }
" Split {
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
nnoremap <silent><Leader>s :execute 'split' PathPrompt('New split name: ', '', 'file')<CR>
nnoremap <silent><Leader>v :execute 'vsplit' PathPrompt('New vsplit name: ', '', 'file')<CR>
" }
" F1 ~ F10 {
nmap <F1> <Plug>CtrlSFPrompt
nnoremap <silent><F2> :CtrlSFToggle<CR>
" }
" Toggle {
nnoremap <silent>cod :<C-R>=&diff ? 'diffoff' : 'diffthis'<CR><CR>
nnoremap <silent>cop :set invpaste<CR>
nnoremap <silent>col :set invlist<CR>
" Disbale paste mode when leaving insert mode
augroup PasteMode
autocmd!
autocmd InsertLeave * setlocal nopaste
augroup END
" }
" Zoom {
" Zoom/Restore window
function! ZoomToggle()
if exists('t:zoomed') && t:zoomed
execute t:zoom_winrestcmd
let t:zoomed = 0
else
let t:zoom_winrestcmd = winrestcmd()
resize
vertical resize
let t:zoomed = 1
endif
endfunction
nnoremap <silent><Leader>z :call ZoomToggle()<CR>
" }
" vim-dirvish {
nnoremap <silent>- :execute 'Dirvish' expand('%:p:h')<CR>
nnoremap <silent>~ :execute 'Dirvish' GetHomePath()<CR>
function! GetRootPath()
let l:root_path = FindRootDirectory()
if l:root_path ==# ''
let l:root_path = expand('%:p:h')
endif
return l:root_path
endfunction
function! GetHomePath()
let l:root_path = FindRootDirectory()
if l:root_path ==# ''
let l:root_path = expand('~')
endif
return l:root_path
endfunction
augroup SplitExplorer
autocmd!
autocmd FileType dirvish silent! unmap <buffer>a
autocmd FileType dirvish silent! unmap <buffer>A
autocmd FileType dirvish silent! unmap <buffer>i
autocmd FileType dirvish silent! unmap <buffer>I
autocmd FileType dirvish silent! unmap <buffer>o
autocmd FileType dirvish silent! unmap <buffer>O
autocmd FileType dirvish noremap - <plug>(dirvish_up)
autocmd FileType dirvish noremap <silent><buffer>o :call dirvish#open('edit', 0)<CR>
autocmd FileType dirvish noremap <silent><buffer>a :call dirvish#open('split', 0)<CR>
autocmd FileType dirvish noremap <silent><buffer>i :call dirvish#open('vsplit', 0)<CR>
autocmd FileType dirvish noremap <silent><buffer>t :call dirvish#open('tabedit', 0)<CR>
augroup END
" }
" vim-asterisk {
map * <Plug>(asterisk-z*)
map g* <Plug>(asterisk-gz*)
map # <Plug>(asterisk-z#)
map g# <Plug>(asterisk-gz#)
" }
" QuickFix {
function! QuickFixToggle(type, cmd)
let l:ftype = &filetype
let l:last_winnr = winnr('#')
let l:buffer_count_before = BufferCount()
if a:type ==# 'quickfix' || a:type ==# 'q'
silent! cclose
elseif a:type ==# 'location' || a:type ==# 'l'
silent! lclose
endif
if BufferCount() == l:buffer_count_before
execute a:cmd
else
if l:ftype is# 'qf'
silent! execute l:last_winnr . 'wincmd w'
endif
endif
endfunction
function! BufferCount()
return len(tabpagebuflist())
endfunction
" }
" vim-qf {
let g:qf_mapping_ack_style = 1
let g:qf_window_bottom = 1
let g:qf_loclist_window_bottom = 1
let g:qf_auto_resize = 1
let g:qf_max_height = 10
let g:qf_auto_open_quickfix = 0
let g:qf_auto_open_loclist = 0
let g:qf_auto_quit = 1
nnoremap <silent><Leader>q :call QuickFixToggle('q', 'silent! botright copen 10')<CR>
nnoremap <silent><Leader>l :call QuickFixToggle('l', 'silent! lopen 10')<CR>
" }
function! Strip(input_string)
return substitute(a:input_string, '^\s*\(.\{-}\)\s*$', '\1', '')
endfunction
" Prompt({prompt_text} [, {default_value} [, {completion_type}]])
" More completion_type, please refer :h command-completion
function! Prompt(prompt_text, ...)
call inputsave()
let l:value = ''
if a:0 == 0
let l:value = input(a:prompt_text)
elseif a:0 == 1
let l:value = input(a:prompt_text, a:1)
else
let l:value = input(a:prompt_text, a:1, a:2)
endif
call inputrestore()
return Strip(l:value)
endfunction
function! PathPrompt(prompt_text, ...)
let l:value = ''
if a:0 == 0
let l:value = Prompt(a:prompt_text)
elseif a:0 == 1
let l:value = Prompt(a:prompt_text, a:1)
else
let l:value = Prompt(a:prompt_text, a:1, a:2)
endif
if l:value ==# ''
let l:value = '%'
endif
return l:value
endfunction
function! Clear()
echon "\r\r"
echon ''
endfunction
" Session {
set sessionoptions-=blank sessionoptions-=options sessionoptions-=folds sessionoptions-=terminal
function! GetSessionFileInfo()
let l:session_dir = expand($HOME . '/.cache/sessions/')
let l:session_filename = l:session_dir . substitute(trim(GetRootPath(), '/', 1), '/', '-', 'g') . '-session.vim'
return [l:session_dir, l:session_filename]
endfunction
function! BackupSession()
let l:session_info = GetSessionFileInfo()
let l:session_dir = l:session_info[0]
let l:session_filename = l:session_info[1]
call mkdir(l:session_dir, 'p')
execute 'Obsession' l:session_filename
endfunction
function! RestoreSession()
let l:session_info = GetSessionFileInfo()
let l:session_filename = l:session_info[1]
if argc() == 0 && filereadable(l:session_filename)
execute 'source' l:session_filename
endif
endfunction
" Backup
nnoremap <Leader>bs :call BackupSession()<CR>
" Remove
nnoremap <Leader>rs :Obsession!<CR>
augroup Session
autocmd!
autocmd VimEnter * nested call RestoreSession()
augroup END
" }
" LeaderF {
let g:Lf_PythonVersion = 3
let g:Lf_ShortcutF = '<C-p>'
let g:Lf_ShortcutB = '<C-m>'
let g:Lf_WindowPosition = 'popup'
let g:Lf_ShowDevIcons = 0
let g:Lf_StlColorscheme = 'powerline'
let g:Lf_StlSeparator = {'left': '', 'right': ''}
let g:Lf_Ctags = 'ctags --fields=+liaS --extras=+q --langmap=c:.c.h,vim:.vim.vimrc'
let g:Lf_PreviewResult = {
\ 'File': 0,
\ 'Buffer': 0,
\ 'Mru': 0,
\ 'Tag': 0,
\ 'BufTag': 0,
\ 'Function': 0,
\ 'Line': 0,
\ 'Colorscheme': 1,
\ 'Rg': 0,
\ 'Gtags': 0
\}
augroup LeaderF
autocmd!
nmap <silent><C-t> :LeaderfBufTag<CR>
nmap <silent><C-y> :LeaderfFunction<CR>
nmap <silent><C-e> :LeaderfLine<CR>
augroup END
" }
" ctrlsf.vim {
let g:ctrlsf_confirm_save = 0
let g:ctrlsf_extra_backend_args = {
\ 'rg': '--hidden',
\ 'ag': '--hidden',
\ }
let g:ctrlsf_ignore_dir = ['.git', '.hg', '.svn', '.bzr']
nmap <silent><Leader>a <Plug>CtrlSFCwordExec
vmap <silent><Leader>a <Plug>CtrlSFVwordExec
" }
" vim-visual-multi {
let g:VM_maps = {}
let g:VM_maps['Select Operator'] = 'gs'
" let g:VM_set_statusline = 0
" }
" vim9-stargate {
let g:stargate_name = 'QMonkey'
" For 1 character to search before showing hints
noremap f <Cmd>call stargate#OKvim(1)<CR>
" For 2 consecutive characters to search
noremap F <Cmd>call stargate#OKvim(2)<CR>
highlight StargateFocus ctermfg=101 guifg=#958C6A
highlight StargateDesaturate ctermfg=238 guifg=#49423F
highlight StargateError ctermfg=167 guifg=#D35B4B
highlight StargateLabels ctermfg=179 ctermbg=234 guifg=#CAA247 guibg=#171E2C
highlight StargateErrorLabels ctermfg=179 ctermbg=52 guifg=#CAA247 guibg=#551414
highlight StargateMain cterm=bold ctermfg=199 gui=bold guifg=#F2119C
highlight StargateSecondary cterm=bold ctermfg=49 gui=bold guifg=#11EB9C
highlight StargateShip ctermfg=233 ctermbg=234 guifg=#111111 guibg=#CAA247
highlight StargateVIM9000 cterm=bold ctermfg=233 ctermbg=139 gui=bold guifg=#111111 guibg=#B2809F
highlight StargateMessage ctermfg=143 guifg=#A5B844
highlight StargateErrorMessage ctermfg=167 guifg=#E36659
" }
" vim-subversive {
nmap s <plug>(SubversiveSubstitute)
xmap s <plug>(SubversiveSubstitute)
nmap ss <plug>(SubversiveSubstituteLine)
nmap S <plug>(SubversiveSubstituteToEndOfLine)
" }
" FastFold {
" Only update fold after type zx or zX
let g:fastfold_fold_command_suffixes = ['x', 'X', 'a', 'A']
let g:fastfold_fold_movement_commands = []
" }
" vim-rooter {
let g:rooter_patterns = ['.root', '.git', '.hg', '.svn', '.bzr', '_darcs', '_FOSSIL_', '.fslckout']
let g:rooter_silent_chdir = 1
let g:rooter_change_directory_for_non_project_files = 'current'
let g:rooter_resolve_links = 1
let g:rooter_manual_only = 1
nnoremap <silent><Leader>cr :Rooter<CR>
augroup ChangeRoot
autocmd!
" Change the working directory on vim startup
autocmd VimEnter * :Rooter
augroup END
" }
" Ctags {
augroup Ctags
autocmd!
" Highlight .tags file as tags file
autocmd BufNewFile,BufRead *.tags setfiletype tags
augroup END
" }
" vim-gutentags {
let g:gutentags_modules = ['ctags']
let g:gutentags_project_root = ['.root', '.git', '.hg', '.svn', '.bzr', '_darcs', '_FOSSIL_', '.fslckout']
let g:gutentags_cache_dir = expand($HOME . '/.cache/tags')
let g:gutentags_ctags_tagfile = '.tags'
let g:gutentags_ctags_auto_set_tags = 1
let g:gutentags_ctags_extra_args = [
\ '--fields=+liaS',
\ '--extras=+q',
\ '--langmap=c:.c.h,vim:.vim.vimrc',
\ '--c-kinds=+p',
\ '--c++-kinds=+p',
\ '--python-kinds=+i',
\]
let g:gutentags_generate_on_missing = 1
let g:gutentags_generate_on_new = 0
let g:gutentags_generate_on_write = 1
let g:gutentags_background_update = 1
let g:gutentags_resolve_symlinks = 1
let g:gutentags_define_advanced_commands = 1
" }
" git-lens.vim {
let g:GIT_LENS_ENABLED = 1
let g:GIT_LENS_CONFIG = {
\ 'blame_delay': 200,
\ 'blame_wrap': v:false,
\ }
" }
" auto-pairs {
let g:AutoPairsMapCh = 1
augroup AutoPairs
autocmd!
" Don't treat double quotes as pairs in vim
autocmd FileType vim let b:AutoPairs = {'(':')', '[':']', '{':'}', "'":"'", '```':'```', '"""':'"""', "'''":"'''", "`":"`"}
augroup END
" }
" vim_current_word {
let g:vim_current_word#highlight_delay = 200
highlight CurrentWord cterm=underline ctermbg=237 gui=underline guibg=#3A3A3A
highlight CurrentWordTwins ctermbg=237 guibg=#3A3A3A
" }
" vim-signature {
" Highlight mark a-zA-Z
highlight SignatureMarkText cterm=bold ctermfg=154 gui=bold guifg=#A6E22E
" Highlight marker !@#$%^&*()
highlight SignatureMarkerText term=bold cterm=bold ctermfg=197 gui=bold guifg=#F92672
let g:SignatureMarkTextHLDynamic = 1