-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
1021 lines (868 loc) · 33.4 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
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
" Vim Set Up
" Language: vim-script
" Author: Junho Lee (TOT0Ro)
let g:vimdir = $HOME .. '/.vim'
" -------------------------------- Plugin -----------------------------------
call plug#begin()
" The default plugin directory will be as follows:
" - Vim (Linux/macOS): '~/.vim/plugged'
" - Vim (Windows): '~/vimfiles/plugged'
" - Neovim (Linux/macOS/Windows): stdpath('data') . '/plugged'
" You can specify a custom plugin directory by passing it as the argument
" - e.g. `call plug#begin('~/.vim/plugged')`
" - Avoid using standard Vim directory names like 'plugin'
Plug 'tpope/vim-sensible' " normal setup
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" File finder
Plug 'ctrlpvim/ctrlp.vim'
" thema (schema)
"Plug 'junegunn/seoul256.vim'
if has('nvim')
Plug 'projekt0n/github-nvim-theme'
endif
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'edkolev/tmuxline.vim'
" keyword tag bar
Plug 'majutsushi/tagbar'
" auto completion
" Need nodejs
" $ curl -sL install-node.vercel.app/lts | bash
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" write comment
Plug 'scrooloose/nerdcommenter'
let g:NERDSpaceDelims=1
" ctags
Plug 'xolox/vim-misc'
" easymotion
Plug 'easymotion/vim-easymotion'
" argument movable
Plug 'peterrincker/vim-argumentative'
" git
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
highlight GitGutterAdd guifg=#009900 ctermfg=82 ctermbg=22
highlight GitGutterChange guifg=#bbbb00 ctermfg=220 ctermbg=130
highlight GitGutterDelete guifg=#ff2222 ctermfg=196 ctermbg=52
" git conlict. required tpope/vim-fugitive
Plug 'christoomey/vim-conflicted'
" line orient
" Plug 'tommcdo/vim-lion'
" MarkDown
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
nmap <leader><leader>m <Plug>MarkdownPreviewToggle
" code break game
Plug 'johngrib/vim-game-code-break'
" REST API
Plug 'diepm/vim-rest-console'
" diff character
" Plug 'vim-scripts/diffchar.vim'
" > Plug ALE
" Plug 'dense-analysis/ale'
" > let g:ale_completion_enabled = 1
" > set omnifunc=ale#completion#OmniFunc
" let g:ale_lint_on_text_changed = 'never'
" let g:ale_lint_on_enter = 0
" Icon
Plug 'ryanoasis/vim-devicons'
" swap recovery
Plug 'chrisbra/Recover.vim'
" indent guide
if has('nvim')
Plug 'lukas-reineke/indent-blankline.nvim'
else
Plug 'nathanaelkane/vim-indent-guides'
let g:indent_guides_enable_on_vim_startup = 1
let g:indent_guides_auto_colors = 0
autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd ctermbg=235 guibg=#262626
autocmd VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=237 guibg=#3a3a3a
let g:indent_guides_guide_size = 1
let g:indent_guides_start_level = 2
let g:indent_guides_default_mapping = 0
endif
" Highlight delimiters
if has('nvim')
Plug 'HiPhish/rainbow-delimiters.nvim'
endif
" docstring
" Need to make install
" $ cd ~/.vim/bundle/vim-pydocstring
" $ make install
Plug 'heavenshell/vim-pydocstring', { 'do': 'make install', 'for': 'python' }
let g:pydocstring_formatter = 'google'
let g:pydocstring_ignore_init = 1
let g:pydocstring_enable_mapping = 0
" quickui
Plug 'skywind3000/vim-quickui'
" fzf
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Shell
Plug 'Shougo/deol.nvim'
" Tab
Plug 'gcmt/taboo.vim'
set sessionoptions+=tabpages,globals
let g:taboo_tab_format=' %f%m%U '
let g:taboo_renamed_tab_format=' <%l>%m%U '
let g:taboo_modified_tab_flag='+'
" Session save
Plug 'tpope/vim-obsession'
let g:obsession_no_bufenter = 1
" Snippets
" Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
" Flutter
Plug 'dart-lang/dart-vim-plugin'
let g:dart_html_in_string = v:true
let g:dart_style_guide = 2
let g:dart_format_on_save = v:true
" Plug 'natebosch/vim-lsc'
" Plug 'natebosch/vim-lsc-dart'
" let g:lsc_auto_map = v:true
" Scrolling
Plug 'opalmay/vim-smoothie'
" let g:smoothie_enabled = 0
let g:smoothie_update_interval = 10
let g:smoothie_speed_exponentiation_factor = 0.99
" Code minimap
Plug 'wfxr/minimap.vim', {'do': ':!cargo install --locked code-minimap'}
let g:minimap_auto_start = 0
let g:minimap_auto_start_win_enter = 0
let g:minimap_width = 15
let g:minimap_exec_warning = 0
let g:minimap_highlight_range = 1
let g:minimap_highlight_search = 1
let g:minimap_git_colors = 1
command! Noh execute 'nohlsearch' | call minimap#vim#ClearColorSearch()
cnoreabbrev noh Noh
" Code context viewer
Plug 'wellle/context.vim'
let g:context_highlight_normal = 'Conceal'
let g:context_highlight_border = '<hide>'
let g:context_highlight_tag = '<hide>'
" Multi Cursor
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
" Initialize plugin system
" - Automatically executes `filetype plugin indent on` and `syntax enable`.
call plug#end()
" You can revert the settings after the call like so:
" filetype indent off " Disable file-type-specific indentation
" syntax off " Disable syntax highlighting
" ------------------------------- setup --------------------------------------
" Uppercase, number of marks, maximum lines are saved for each register,
" size limit for a register, nohisearch
set viminfo=!,'1000,<1000,s100,/1000,:1000,@1000,h
" May need for Vim (not Neovim) since coc.nvim calculates byte offset by count
" utf-8 byte sequence
set encoding=utf-8
" Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
" delays and poor user experience
set updatetime=300
set signcolumn=yes
highlight SignColumn ctermbg=none
set fencs=utf-8,euc-kr,ucs-bom,korea
set background=dark
" set t_Co=16
set t_Co=256
set autoread
autocmd CursorHold * :checktime
set hlsearch
if has('nvim')
" ColorScheme
colorscheme github_dark_colorblind
set winhighlight=Normal:MyNormal,NormalNC:MyNormalNC,NormalSB:MyNormalNC,NormalFloat:MyNormalNC
highlight Normal guifg=#c9d1d9 guibg=None
highlight NormalNC guibg=NONE
highlight NormalFloat guibg=NONE
highlight NormalSB guibg=NONE
highlight MyNormal guifg=#c9d1d9 guibg=#0d1117 " github_dark_colorblind
highlight MyNormalNC guifg=#c9d1d9 guibg=None
" Use mount options
set mouse=v
endif
set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set autoindent
set smartindent
set textwidth=100
set formatoptions-=t
autocmd FileType c setlocal ts=8 sts=8 sw=8 noexpandtab cc=+0 tw=80
autocmd FileType cpp setlocal ts=8 sts=8 sw=8 noexpandtab cc=+0
autocmd FileType vim setlocal ts=4 sts=4 sw=4 expandtab cc=+0
autocmd FileType python setlocal ts=4 sts=4 sw=4 expandtab tw=88 cc=+0
autocmd FileType markdown setlocal ts=4 sts=4 sw=4 expandtab tw=100 cc=+0
autocmd FileType html setlocal ts=4 sts=4 sw=4 expandtab tw=100 cc=+0
" --------------------------- COMMIT_EDITMSG ---------------------------------
autocmd BufEnter COMMIT_EDITMSG set textwidth=72 cc=+0 formatoptions+=t
autocmd BufEnter COMMIT_EDITMSG highlight CommitEditor ctermbg=105 cterm=None guibg=#8787ff
autocmd BufEnter COMMIT_EDITMSG match CommitEditor '\%1l\%50v'
" ------------------------- 라인 끝 공백 highlight --------------------------
highlight ExtraWhitespace ctermbg=88 guibg=#870000
match ExtraWhitespace /\s\+$/
function! ExtraWhitespaceIfNofile()
if &buftype ==# '' && &bufhidden ==# ''
match ExtraWhitespace /\s\+$/
endif
endfunction
autocmd WinEnter * call ExtraWhitespaceIfNofile()
autocmd WinLeave * call clearmatches()
" ---------------------------------- folding ---------------------------------
set foldmethod=manual
set foldnestmax=2
set foldlevel=0
set foldcolumn=0
exec 'set fillchars=fold:\ '
function! MyFoldText()
let nl = v:foldend - v:foldstart + 1
let txt = getline(v:foldstart) .. ' --- length ' .. nl .. ' '
return txt
endfunction
set foldtext=MyFoldText()
nnoremap <space><space> za
vnoremap <space><space> zf
highlight FoldColumn ctermfg=3 ctermbg=none guifg=#808000
highlight Folded ctermfg=245 ctermbg=none guifg=#8a8a8a
let foldfiles = {
\ 'python': g:vimdir .. '/python_fold.vim'
\}
" let python_fold = findfile(foldfiles.python)
if exists("python_fold")
exec 'autocmd FileType python source ' .. python_fold
endif
function! FindDeepestFoldLevel()
let maxFoldLevel = 0
for i in range(1, line('$'))
let currentFoldLevel = foldlevel(i)
if currentFoldLevel > maxFoldLevel
let maxFoldLevel = currentFoldLevel
endif
endfor
return maxFoldLevel
endfunction
function! ToggleFoldColumn()
if &foldcolumn
set foldcolumn=0
else
let max_fold_level = FindDeepestFoldLevel()
if max_fold_level > 0
let max_fold_level += 1
endif
exec 'set foldcolumn=' .. max_fold_level
endif
endfunction
command! FoldColumn call ToggleFoldColumn()
" -------------------------------- quick fix --------------------------------
function! OpenQuickfixWindow()
let length = len(getqflist())
if length > 10
let length = 10
endif
if length > 1
exec "copen" .. length
else
exec "cclose"
endif
endfunction
autocmd QuickFixCmdPost * :call OpenQuickfixWindow()
" autocmd BufReadPost quickfix setlocal modifiable
" \ | silent exec 'g/^/s//\=line(".")." "/'
" \ | setlocal nomodifiable
" -------------------------------- cursor ------------------------------------
set cursorline
set cursorcolumn
function! ToggleCursorHighlight ()
if &cursorline && &cursorcolumn
set nocursorline
set nocursorcolumn
else
set cursorline
set cursorcolumn
endif
endfunction
" ------------------------------- ruler --------------------------------------
autocmd BufReadPre * let b:colorcolumns = &cc
function! ToggleRuler ()
if &cc != '0'
let b:colorcolumns = &cc
exec 'set cc=0'
else
if !exists('b:colorcolumns')
let b:colorcolumns = 0
endif
exec 'set cc=' .. b:colorcolumns
endif
endfunction
hi CursorLine ctermbg=237 cterm=None guibg=#3a3a3a
hi CursorColumn ctermbg=237 cterm=None guibg=#3a3a3a
hi ColorColumn ctermbg=105 cterm=None guibg=#8787ff
" syntax enable
" set wmnu
" set nu
" ------------------------------- diff ----------------------------------------
" diff
highlight DiffAdd ctermbg=22 guibg=#005f00
highlight DiffChange ctermbg=54 guibg=#5f0087
highlight DiffDelete ctermbg=88 guibg=#870000
highlight DiffText ctermbg=237 guibg=#3a3a3a
" --------------------------- statusbar/ airline ------------------------------
set laststatus=2 " vim-airline을 위해 상태바 2줄
if 1
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
" let g:airline#extensions#tabline#left_sep = ''
" let g:airline#extensions#tabline#left_alt_sep = ''
" let g:airline#extensions#tabline#right_sep = ''
" let g:airline#extensions#tabline#right_alt_sep = ''
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = ' '
let g:airline#extensions#tabline#right_sep = ' '
let g:airline#extensions#tabline#right_alt_sep = ' '
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline#extensions#tabline#tab_nr_type = 1
let g:airline#extensions#tabline#show_tab_nr = 1
let g:airline#extensions#tabline#tabtitle_formatter = 'TabTitleFormatter'
function TabTitleFormatter(n)
return TabooTabTitle(0)
endfunction
let g:airline_theme='simple'
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_left_alt_sep = ''
let g:airline_right_alt_sep = ''
" let g:airline_left_sep = ''
" let g:airline_right_sep = ''
let g:airline_symbols.paste = ' '
let g:airline_left_sep = ' '
let g:airline_right_sep = ' '
" let g:airline_symbols.paste = 'PASTE'
function! GetObsessionSymbol()
let status = g:obsession_status
return status == 2 ? '' : status == 1 ? ' ' : ' '
" return status == 2 ? '' : status == 1 ? '$' : 'S'
endfunction
call airline#parts#define(
\ 'obsessionstatus', {'function': 'GetObsessionSymbol', 'accents': 'bold'})
function! GetWindowNumber()
return ' ' .. tabpagewinnr(tabpagenr())
" return ' W' .. tabpagewinnr(tabpagenr())
endfunction
call airline#parts#define(
\ 'windownumber', {'function': 'GetWindowNumber', 'accents': 'bold'})
function! GetFoldLevel()
return foldlevel(line('.')) > 0 ? ' ' .. foldlevel(line('.')) : ''
" return foldlevel(line('.')) > 0 ? ' Z' .. foldlevel(line('.')) : ''
endfunction
call airline#parts#define(
\ 'foldlevel', {'function': 'GetFoldLevel', 'accents': 'bold'})
let g:airline_section_a = airline#section#create_left(
\ ['mode', 'crypt', 'paste', 'keymap', 'spell', 'capslock', 'xkblayout', 'iminsert', 'obsessionstatus'])
let g:airline_section_z = airline#section#create(
\ ['%p%%', 'linenr', 'maxlinenr', 'colnr', 'foldlevel', 'windownumber'])
endif
let g:airline#extensions#tmuxline#enabled = 0
let g:tmuxline_preset = {
\'a' : '#S',
\'b' : '#W',
\'c' : '#H',
\'win' : ['#I', '#W#F'],
\'cwin' : ['#I', '#W#F'],
\'x' : "#(date)",
\'y' : "#(uptime | cut -f 4-5 -d ' ' | cut -f 1 -d ',')",
\'z' : "#H"}
let g:tmuxline_separators = {
\ 'left' : '',
\ 'left_alt': '',
\ 'right' : '',
\ 'right_alt' : '',
\ 'space' : ' '}
" -------------------------- coc ----------------------------------------------
if 1
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1) :
\ "\<TAB>"
" \ CheckBackspace() ? "\<TAB>" :
" \ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" inoremap <silent><expr> <TAB>
" \ coc#pum#visible() ? coc#_select_confirm() :
" \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
" \ CheckBackspace() ? "\<TAB>" :
" \ coc#refresh()
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" GoTo code navigation
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gt <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
" Highlight the symbol and its references when holding the cursor
if exists('*CocActionAsync')
autocmd CursorHold * silent call CocActionAsync('highlight')
endif
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s)
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap <C-f> and <C-b> to scroll float windows/popups
if has('nvim-0.4.0') || has('patch-8.2.0750')
nnoremap <silent><nowait><expr> <C-f>
\ coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
nnoremap <silent><nowait><expr> <C-b>
\ coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
inoremap <silent><nowait><expr> <C-f>
\ coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
inoremap <silent><nowait><expr> <C-b>
\ coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
vnoremap <silent><nowait><expr> <C-f>
\ coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
vnoremap <silent><nowait><expr> <C-b>
\ coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif
" Mappings for CoCList
" Show all diagnostics
" Do default action for next item
nnoremap <silent><nowait> <leader>j :<C-u>CocNext<CR>
" Do default action for previous item
nnoremap <silent><nowait> <leader>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent><nowait> <leader>; :<C-u>CocListResume<CR>
" Jump to next/previous problem
nmap <silent> [g <Plug>(coc-diagnostic-next)
nmap <silent> ]g <Plug>(coc-diagnostic-prev)
" Prettier (coc-prettier)
vmap <leader><leader>p <Plug>(coc-format-selected)
nmap <leader><leader>p <Plug>(coc-format-selected)
" Snippets
"
" Use <C-l> for trigger snippet expand.
imap <C-l> <Plug>(coc-snippets-expand)
" Use <C-j> for select text for visual placeholder of snippet.
vmap <C-j> <Plug>(coc-snippets-select)
" Use <C-j> for jump to next placeholder, it's default of coc.nvim
let g:coc_snippet_next = '<c-j>'
" Use <C-k> for jump to previous placeholder, it's default of coc.nvim
let g:coc_snippet_prev = '<c-k>'
" Use <C-j> for both expand and jump (make expand higher priority.)
imap <C-j> <Plug>(coc-snippets-expand-jump)
" Use <leader>x for convert visual selected code to snippet
xmap <leader>x <Plug>(coc-convert-snippet)
let g:coc_global_extensions = [
\ 'coc-yank',
\ 'coc-json',
\ 'coc-html',
\ 'coc-diagnostic',
\ 'coc-sh',
\ 'coc-pyright',
\ 'coc-markdownlint',
\ 'coc-docker',
\ 'coc-clangd',
\ 'coc-css',
\ 'coc-snippets',
\ 'coc-yaml',
\ 'coc-flutter',
\ 'coc-cmake'
\ ]
" coc-clangd --> sudo apt-get install clangd-12
nnoremap <silent> <leader>p :<C-u>CocList -A --normal yank<cr>
autocmd FileType css setl iskeyword+=-
autocmd FileType scss setl iskeyword+=@-@
endif
" ------------------------------- Obsession ----------------------------------
" Obsession status
" - 0: disable
" - 1: enable
" - 2: not use
function! ObsessionToggle()
if g:obsession_status == 2
execute "Obsession " .. g:obsession_swap
let g:obsession_status = 1
else
execute "Obsession"
let g:obsession_status = xor(g:obsession_status, 1)
endif
endfunction
function! ObsessionDelete()
if g:obsession_status != 2
execute "Obsession!"
let g:obsession_status = 2
call delete(g:obsession_file)
endif
endfunction
if has('nvim')
let g:obsession_dir = g:vimdir .. '/neo_obsession'
else
let g:obsession_dir = g:vimdir .. '/obsession'
endif
if !isdirectory(g:obsession_dir)
call mkdir(g:obsession_dir, "p", 0700)
endif
let g:obsession_filename = slice(substitute($PWD .. '/Session.vim', '/', '-', 'g'), 1)
let g:obsession_file = g:obsession_dir .. '/' .. g:obsession_filename
let g:obsession_swap = g:obsession_file .. '.swp'
" If Obsession is used and exist session swap file, to store session file.
function! ObsessionLeave()
if (g:obsession_status != 2 && !empty(findfile(g:obsession_swap)))
call writefile(readfile(g:obsession_swap), g:obsession_file)
call delete(g:obsession_swap)
endif
endfunction
au VimLeave * call ObsessionLeave()
" If executes without arguments and anybody is not use Obsession,
" load session file and enable Obsession.
if !get(g:, 'obsession_status')
let g:obsession_status = 2
if (!argc() && !empty(findfile(g:obsession_file)) && empty(findfile(g:obsession_swap)))
call writefile(readfile(g:obsession_file), g:obsession_swap)
let g:obsession_status = 1
execute 'silent source ' .. g:obsession_swap
endif
endif
" ------------------------------- tags ----------------------------------------
" pycscope 이용
" find ./ -name "*.[ch]" –print > cscope.files
" cscope -RUbq
"
" sed 's/\(.*\)\/$/\1/' .gitignore | sed '/^#/d'
" ctags -R --exclude='@tags.ignore' -n
" ------------------------------------------- Set up Guide
" ctags
autocmd BufEnter * exec "set tags=./tags,tags," .. findfile("tags", ".;")
" cscope
function! LoadCscope()
let db = findfile("cscope.out", ".;")
if (!empty(db))
let path = strpart(db, 0, match(db, "/cscope.out$"))
set nocscopeverbose
exe "cs add " .. db .. " " .. path
" exe "cs add " .. db
set cscopeverbose
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
endfunction
au BufEnter /* call LoadCscope()
if !has('nvim')
set cscopequickfix=s-,g-,d-,c-,t-,e-,f-,i-,a-
set csto=1
set cst
nmap <Plug>CscopeFindSym :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <Plug>CscopeFindDef :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <Plug>CscopeFindClr :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <Plug>CscopeFindCll :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <Plug>CscopeFindTxt :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <Plug>CscopeFindGrp :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <Plug>CscopeFindFle :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <Plug>CscopeFindInc :cs find d <C-R>=expand("<cword>")<CR><CR>
nmap <Plug>CscopeFindAsn :cs find a <C-R>=expand("<cword>")<CR><CR>
nmap <Plug>CscopeFindStc :cs find t struct <C-R>=expand("<cword>")<CR> {<CR>
nmap <silent><leader>s <Plug>CscopeFindSym
nmap <silent><leader>g <Plug>CscopeFindDef
nmap <silent><leader>c <Plug>CscopeFindClr
nmap <silent><leader>t <Plug>CscopeFindCll
nmap <silent><leader>e <Plug>CscopeFindTxt
nmap <silent><leader>f <Plug>CscopeFindGrp
nmap <silent><leader>i <Plug>CscopeFindFle
nmap <silent><leader>d <Plug>CscopeFindInc
nmap <silent><leader>a <Plug>CscopeFindAsn
nmap <silent><leader>S <Plug>CscopeFindStc
endif
" -------------------------- fzf(command-line fuzzy finder --------------------
let fzfdir = $HOME .. '/.fzf'
exec 'set rtp+=' .. fzfdir
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit' }
" - Popup window (center of the current window)
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true } }
" Customize fzf colors to match your color scheme
" - fzf#wrap translates this to a set of `--color` options
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" Enable per-command history
" - History files will be stored in the specified directory
" - When set, CTRL-N and CTRL-P will be bound to 'next-history' and
" 'previous-history' instead of 'down' and 'up'.
let g:fzf_history_dir = '~/.local/share/fzf-history'
nmap <Plug>SearchGitFile
\ :call fzf#run({'source': 'git ls-files', 'sink': 'e', 'left': '40%'})<CR>
" The query history for this command will be stored as 'ls' inside g:fzf_history_dir.
" The name is ignored if g:fzf_history_dir is not defined.
command! -bang -complete=dir -nargs=? LS
\ call fzf#run(fzf#wrap('ls', {'source': 'ls', 'dir': <q-args>}, <bang>0))
" ------------------------- quickui -------------------------------------------
if 1
function! PopupLines()
let lines = &lines - 5
if &lines > 25
let lines = 25
endif
return lines
endfunction
function! PopupColumns()
let columns = &columns - 20
if &columns > 120
let columns = 100
endif
return columns
endfunction
function! QuickuiSaveBackup()
let versionname = quickui#input#open('Enter version name:', 'old')
call SaveBackup(versionname)
endfunction
" default menu
call quickui#menu#switch('def')
" clear all the menus
call quickui#menu#reset()
call quickui#menu#install("&Files", [
\ ['&Paste', "set paste!"],
\ ['--',''],
\ ['S&croll bar', "MinimapToggle"],
\ ['&NERD Tree', "NERDTreeToggle"],
\ ['&Tag Bar', "TagbarToggle"],
\ ['--',''],
\ ['Search &Git File', "normal \<Plug>SearchGitFile"],
\ ['--',''],
\ ['&Save Session Toggle', "call ObsessionToggle()"],
\ ['&Delete Session', "call ObsessionDelete()"],
\ ['--',''],
\ ['Save Backup', "call QuickuiSaveBackup()"],
\ ['Delete Swap', "call DeleteSwap()"],
\ ])
call quickui#menu#install("&Tags", [
\ ['Function &List', "call quickui#tools#list_function()"],
\ ['Preview &Tag <F3>', ":call quickui#tools#preview_tag('')"],
\ ])
function! TermExit(code)
echom "terminal exit code: " .. a:code
endfunc
function! OpenShell()
let opts = {'w':call("PopupColumns",[]),
\ 'h':call("PopupLines",[]), 'callback':'TermExit'}
let opts.title = 'Terminal Popup'
call quickui#terminal#open('bash', opts)
endfunction
function! OpenPython()
let opts = {'w':call("PopupColumns",[]),
\ 'h':call("PopupLines",[]), 'callback':'TermExit'}
let opts.title = 'Python Popup'
call quickui#terminal#open(
\ 'bash -c "if [ ! -z $(which ipython) ]; then ipython; else python; fi"',
\ opts)
endfunction
function! TabRename()
let previous_tabname = TabooTabName(0)
let tabname = quickui#input#open('Enter this tab name', previous_tabname)
execute "TabooRename " .. tabname
endfunction
call quickui#menu#install("&Window", [
\ ['Buffer &Delete', 'bdelete'],
\ ['Tab &New', 'tabnew'],
\ ['Tab &Close', 'tabclose'],
\ ['Tab &Rename', 'call TabRename()'],
\ ['Tab NameReset', 'TabooReset'],
\ ['--',''],
\ ['&Shell', 'call OpenShell()'],
\ ['&Python', 'call OpenPython()'],
\ ['&Messages', 'Messages'],
\ ['--',''],
\ ['Toggle &FoldColumn', 'call ToggleFoldColumn()'],
\ ['Toggle Cursor High&light', 'call ToggleCursorHighlight()'],
\ ['Toggle Color R&uler', 'call ToggleRuler()'],
\ ['--',''],
\ ['&Buffer Switcher <F4>', 'call quickui#tools#list_buffer("e")'],
\ ])
call quickui#menu#install("Coc &Refactor", [
\ ['Code &Action', "call CocActionAsync('codeAction', visualmode())"],
\ ['Code Action &Cursor', "normal \<Plug>(coc-codeaction-cursor)"],
\ ['Code Action &Source', "normal \<Plug>(coc-codeaction-source)"],
\ ['Code Action S&elected', "normal \<Plug>(coc-codeaction-selected)"],
\ ['&Rename', "normal \<Plug>(coc-rename)"],
\ ])
call quickui#menu#install("&CocList", [
\ ['&Diagnostics', 'CocList diagnostics'],
\ ['&Extensions', 'CocList extensions'],
\ ['&Commands', 'CocList commands'],
\ ['&Outline', 'CocList outline'],
\ ['&Symbols', 'CocList symbols'],
\ ['Sni&ppets', 'CocList snippets'],
\ ])
" register HELP menu with weight 10000
call quickui#menu#install('Help (&?)', [
\ ["&Index", 'tab help index', ''],
\ ['Ti&ps', 'tab help tips', ''],
\ ['--',''],
\ ["&Tutorial", 'tab help tutor', ''],
\ ['&Quick Reference', 'tab help quickref', ''],
\ ['&Summary', 'tab help summary', ''],
\ ['--',''],
\ ['&Vim Script', 'tab help eval', ''],
\ ['&Function List', 'tab help function-list', ''],
\ ['&Dash Help', 'call asclib#utils#dash_ft(&ft, expand("<cword>"))'],
\ ], 10000)
" enable to display tips in the cmdline
let g:quickui_show_tip = 1
" hit space twice to open menu
noremap <F1> :call quickui#menu#open()<cr>
call quickui#menu#open('default')
let g:quickui_border_style = 2
let g:quickui_color_scheme = 'gruvbox'
autocmd VimResized * let g:quickui_preview_w = 100
autocmd VimResized * let g:quickui_preview_h = 20
" display vim messages in the textbox
function! DisplayMessages()
let x = ''
redir => x
silent! messages
redir END
let x = substitute(x, '[\n\r]\+\%$', '', 'g')
let content = filter(split(x, "\n"), 'v:key != ""')
let opts = {"close":"button", "title":"Vim Messages"}
call quickui#textbox#open(content, opts)
endfunc
command -nargs=0 Messages call DisplayMessages()
let cursor_context_content = [
\ ['Find Symbols \s', "normal \<Plug>CscopeFindSym"],
\ ['Find Definition \g', "normal \<Plug>CscopeFindDef"],
\ ['Find Functions Called by \c', "normal \<Plug>CscopeFindClr"],
\ ['Find Functions Calling \t', "normal \<Plug>CscopeFindCll"],
\ ['Find Text String \e', "normal \<Plug>CscopeFindTxt"],
\ ['Find Egrep Pattern \f', "normal \<Plug>CscopeFindGrp"],
\ ['Find File \i', "normal \<Plug>CscopeFindFle"],
\ ['Find Files #including \d', "normal \<Plug>CscopeFindInc"],
\ ['Find where value assigned \a', "normal \<Plug>CscopeFindAsn"],
\ ['Find Struct \S', "normal \<Plug>CscopeFindStc"],
\ ['-'],
\ ['Code Action &Cursor', "normal \<Plug>(coc-codeaction-cursor)"],
\ ['Code Action &source', "normal \<Plug>(coc-codeaction-source)"],
\ ['Code Action S&elected', "normal \<Plug>(coc-codeaction-selected)"],
\ ['&Rename', "normal \<Plug>(coc-rename)"],
\ ]
" set cursor to the last position
let cursor_context_opts = {'index':g:quickui#context#cursor}
noremap <F2> :call quickui#context#open(cursor_context_content, cursor_context_opts)<cr>
augroup MyQuickfixPreview
au!
au FileType qf noremap <silent><buffer> p :call quickui#tools#preview_quickfix()<cr>
augroup END
endif
" --------------------------------- Key Mapping -------------------------------
" Editor
" Should be -n options when making tags
nnoremap <F3> :call quickui#tools#preview_tag('')<cr>
nnoremap <F4> :call quickui#tools#list_buffer("e")<cr>
" buffer
nnoremap <F5> :bp<cr>
nnoremap <F6> :bn<cr>
" tab
nnoremap <F7> :tabp<cr>
nnoremap <F8> :tabn<cr>
" undo remap
nnoremap U <C-r>
" like Shift-enter
inoremap <C-r> <ESC>o
" window
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" highlight
nnoremap <leader><leader>/ :noh<cr>
" -------------------------------- save backup -------------------------------
" 버전별 save 만들기
function! SaveBackup (versionname)
if a:versionname != ''
call writefile(getline(1,'$'),
\ expand('%:p') .. '.bak.' .. a:versionname)
endif
endfunction
command! SaveBackup call SaveBackup(input('Enter backup version name: ', strftime("%Y%m%d_%H%M%S")))
" -------------------------- skel file ---------------------------------------
let blog_skel = findfile("_draft/skel.md", ".;")
if (!empty(blog_skel))
exec 'autocmd BufNewFile *.md 0read ' .. blog_skel
endif
let c_skel = findfile(".skel/skel.c", ".;")
if (!empty(c_skel))
exec 'autocmd BufNewFile *.c 0read ' .. c_skel
endif
" ----------------------------- undo history ---------------------------------
" undofile directory
if has('nvim')
let undofile_path = g:vimdir . "/neo_undo"
else
let undofile_path = g:vimdir . "/undo"
endif
if !isdirectory(undofile_path)
call mkdir(undofile_path, "p", 0700)
endif
exec 'set undodir=' .. undofile_path
set undofile
" ---------------------------- swap ------------------------------------------
" swap directory
if has('nvim')
let swapfile_path = g:vimdir .. '/neo_temp'