-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvimrc
1227 lines (1141 loc) · 42.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
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
" Author: Yuxin Wu
set nocompatible " Use Vim Settings (Not Vi). This must be first, because it changes other options as a side effect.
" Needs to be set before lazy.
let mapleader=" "
let maplocalleader=","
if has('nvim') " Plugins for neovim: f[[
lua << EOF
local lazypath = vim.fn.stdpath("config") .. "/bundle/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git",
"--branch=stable", lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local plugins = {}
local use = function(x) table.insert(plugins, x) end
-- UI And Basic:
use {'folke/tokyonight.nvim', lazy = false, opts = {
on_colors = function(c)
c.gitSigns = { add = '#00dd00', change = '#00c0ff', delete = '#ff3030' }
c.ui_bg = '#24283b'
end,
on_highlights = function(hl, c)
for k in pairs(hl) do
-- Only keep the following, others are set by 'default' colorscheme.
-- See https://github.com/folke/tokyonight.nvim/blob/main/lua/tokyonight/theme.lua
if vim.startswith(k, "Cmp") or vim.startswith(k, "WhichKey") then goto continue end
if vim.startswith(k, "Lsp") or vim.startswith(k, "@lsp") then goto continue end
if vim.startswith(k, "Diagnostic") then goto continue end
if vim.startswith(k, "@string") or vim.startswith(k, "@text") then goto continue end
if vim.startswith(k, "GitGutter") then
hl[k]["bg"] = c.ui_bg; goto continue
end
hl[k] = nil
::continue::
end
for _, k in ipairs({"Pmenu", "TreesitterContext", "TreesitterContextLineNumber", "SignColumn"}) do
hl[k] = { bg = c.ui_bg }
end
for _, k in ipairs({"Error", "Warn", "Hint", "Info"}) do
hl["DiagnosticSign" .. k] = { bg = c.ui_bg, fg = hl["Diagnostic" .. k ].fg}
end
hl["CmpPmenu"] = {bg = c.ui_bg, fg = '#c9f0f0'} -- For nvim-cmp completion
hl["TreesitterContextLineNumber"]["fg"] = c.ui_bg -- Hide line number
end }}
use {'glepnir/dashboard-nvim', event = 'VimEnter', opts = {
theme = 'hyper',
config = {
week_header = { enable = true },
shortcut = {
{ desc = ' Recent Files', group = 'Label',
action = 'Telescope oldfiles', key = 'r' },
{
desc = ' dotfiles', group = 'Number', key = 'd',
action = function()
local resolve = function(path)
local path = vim.fs.normalize(path)
local truepath = vim.fn.resolve(path)
return (truepath ~= path) and vim.fs.dirname(truepath) or ''
end
require('telescope.builtin').find_files{
layout_strategy = 'vertical',
find_command = {
"rg", "--files", resolve('~/.vimrc'), resolve('~/.zshrc'), "--hidden",
"--glob", "!pixmaps", "--glob", "!.git"
}}
end },
},
},
}}
-- https://github.com/Yggdroot/indentLine/issues/345
use {'Yggdroot/indentLine', config = function()
vim.g.indentLine_enabled = 0
vim.g.indentLine_color_term = 239
vim.g.indentLine_color_gui = '#A4E57E'
end }
use {'vim-scripts/searchfold.vim', keys = {'<Leader>z'}}
use 'vim-scripts/LargeFile'
use {'folke/which-key.nvim', branch = 'main'}
use {'lambdalisue/suda.vim', cmd = 'SudaWrite'}
use 'nvim-lualine/lualine.nvim'
-- https://github.com/folke/lazy.nvim/issues/389
vim.g.skip_ts_context_commentstring_module = true -- https://github.com/JoosepAlviste/nvim-ts-context-commentstring
use {'nvim-treesitter/nvim-treesitter', build = ':TSUpdate', event = "BufReadPost",
opts = {
-- Do not enable for comment
ensure_installed = { 'bash', 'c', 'cmake', 'cpp', 'cuda', 'glsl', 'css', 'html', 'javascript', 'json', 'lua', 'make', 'markdown', 'ninja', 'proto', 'python', 'rst', 'scss', 'typescript', 'vim' },
highlight = { enable = true, },
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<C-space>",
node_incremental = "<C-space>",
scope_incremental = false,
node_decremental = "<bs>",
},
},
},
config = function(p, opts) require("nvim-treesitter.configs").setup(opts) end,
dependencies = 'JoosepAlviste/nvim-ts-context-commentstring'
}
use {'nvim-treesitter/playground', cmd = 'TSHighlightCapturesUnderCursor'}
use {'nvim-treesitter/nvim-treesitter-context',
opts = { min_window_height = 20, max_lines = 3 },
event = "BufReadPost" }
use {'dstein64/vim-startuptime', cmd = 'StartupTime', commit = 'ac2cccb5be617672add1f4f3c0a55ce99ba34e01'}
use 'vim-scripts/MultipleSearch'
use 'ppwwyyxx/vim-PinyinSearch'
-- Window Tools:
use {'mbbill/undotree', cmd = 'UndotreeToggle'}
use 'nvim-lua/plenary.nvim'
use {'nvim-telescope/telescope.nvim', lazy = true, opts = {
defaults = {
prompt_prefix = '🔍',
layout_strategy = 'flex',
layout_config = {
width = 0.9,
flex = { flip_columns = 120 },
horizontal = { preview_width = 0.6 },
vertical = { preview_height = 0.3 }
},
path_display = { truncate = 2 },
mappings = {
i = {
["<C-s>"] = "file_split",
["<Esc>"] = "close",
["<C-j>"] = "move_selection_next",
["<C-k>"] = "move_selection_previous",
}
},
}},
config = function(p, opts)
require('telescope').setup(opts)
require('telescope').load_extension('fzf')
require('telescope').load_extension('aerial')
end,
cmd = 'Telescope'
}
use {'nvim-telescope/telescope-fzf-native.nvim', build = 'make', branch = 'main', lazy = true }
use {'nvim-tree/nvim-tree.lua', dependencies = 'nvim-tree/nvim-web-devicons'}
use {'preservim/tagbar', cmd = 'TagbarToggle'}
use {'stevearc/aerial.nvim', opts = {
attach_mode = 'global',
autojump = true,
placement = 'edge',
highlight_on_hover = true,
ignore = {filetypes = {'vim'}},
nav = { autojump = true },
}}
use {'ii14/neorepl.nvim', commit = 'bc819bb42edca9c4a6b6e5d00f09f94a49c3b735', lazy = true }
use {'NvChad/nvim-colorizer.lua', ft = {'css', 'html', 'vim'},
opts = { user_default_options = { names = false } } }
-- Editing Tools:
use {'rhysd/accelerated-jk', lazy = false, commit = '156c5158b72059404f6b8aaf15b59f87dd0aaa88'}
use {'yonchu/accelerated-smooth-scroll', lazy = false, commit = '04944ea4831f5d31f776cb8cd627601ddb567fc2'}
use {'tsaleh/vim-align', cmd = {'Align', 'AlignCtrl'}, commit = 'fa5fdeeea25269c3e83262c03dfa1ccd27dbd3c9' }
use 'tpope/vim-surround'
use {'hadronized/hop.nvim',
opts = { keys = 'etovxqpdygfblzhckisuran', jump_on_sole_occurrence = false },
keys = {{',w', ':HopWord<cr>', mode='n'}},
commit = '1a1eceafe54b5081eae4cb91c723abd1d450f34b'
}
use {'ojroques/vim-oscyank', branch = 'main'}
vim.g.matchmaker_enable_startup = 1 -- highlight words under cursor
use {'qstrahl/vim-matchmaker'} -- delay loading so it can read the config
use 'preservim/nerdcommenter'
use {'glts/vim-textobj-comment', dependencies = 'kana/vim-textobj-user'}
use {'kana/vim-textobj-indent', dependencies = 'kana/vim-textobj-user'}
-- Programming:
use {'ruanyl/vim-gh-line', event = 'VimEnter'} -- delay init to pickup configs.
use {'f-person/git-blame.nvim', opts = { enabled = false, date_format = '%r' }}
use {'derekwyatt/vim-fswitch', ft = {'cpp', 'c'}}
use {'airblade/vim-gitgutter', event = 'VimEnter'}
use {'wakatime/vim-wakatime', cond = vim.fn.filereadable(vim.fn.expand('$HOME/.wakatime.cfg')) == 1 }
-- LSP:
use {'neovim/nvim-lspconfig', lazy = true}
use {'onsails/lspkind.nvim', config = function()
require("lspkind").init({ symbol_map = { Class = "", Struct = "", Copilot = " " } })
-- https://github.com/zbirenbaum/copilot-cmp#highlighting--icon
vim.api.nvim_set_hl(0, "CmpItemKindCopilot", {fg ="#6CC644"})
end, event = "LspAttach" }
-- use { 'github/copilot.vim', cmd = 'Copilot', config = function() vim.g.copilot_no_tab_map = true end }
use { 'zbirenbaum/copilot.lua', opts = { suggestion = { enabled = false }, panel = { enabled = false } }}
use { 'zbirenbaum/copilot-cmp', config = function () require("copilot_cmp").setup() end }
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-buffer'
use { 'hrsh7th/cmp-nvim-lsp', dependencies = {'hrsh7th/cmp-vsnip', 'hrsh7th/vim-vsnip', 'hrsh7th/cmp-nvim-lsp-signature-help' }, event = "LspAttach" }
use { 'hrsh7th/cmp-nvim-lua', ft = {'lua', 'vim'}}
use 'hrsh7th/cmp-cmdline'
use { 'hrsh7th/nvim-cmp' }
use {'folke/trouble.nvim', lazy = true, dependencies = 'nvim-tree/nvim-web-devicons', opts = {
action_keys = {
open_split = { "<c-s>" }, -- open buffer in new split
open_tab = {},
},
auto_close = true, -- automatically close the list when you have no diagnostics
use_diagnostic_signs = true, -- enabling this will use the signs defined in your lsp client
}, cmd = {'Trouble', 'TroubleToggle', 'TroubleClose'}}
-- Syntax:
use 'dense-analysis/ale'
use 'vim-scripts/gprof.vim'
use {'smilekzs/vim-coffee-script', ft = 'coffee'}
use {'chrisbra/csv.vim', ft = 'csv'}
use {'digitaltoad/vim-jade', ft = 'jade'}
use {'maksimr/vim-jsbeautify', ft = {'html', 'javascript', 'css', 'json'}}
use {'pangloss/vim-javascript', ft = 'javascript'}
use {'groenewege/vim-less', ft = 'less'}
use {'fs111/pydoc.vim', ft = 'python'}
use {'slim-template/vim-slim', ft = 'slim'}
use {'wavded/vim-stylus', ft = 'stylus'}
use {'jeroenbourgois/vim-actionscript', ft = 'actionscript'}
if vim.fn.filereadable(vim.fn.stdpath("config") .. "/lua/local_plugin.lua") == 1 then
use {import = 'local_plugin'}
end
-- List vim-specific plugins so they don't get cleaned.
for _, p in ipairs({'vim-airline/vim-airline', 'vim-airline/vim-airline-themes', 'ctrlpvim/ctrlp.vim', 'scrooloose/nerdtree'}) do
use {p, lazy = true}
end
require("lazy").setup(plugins, {
root = vim.fn.stdpath("config") .. "/bundle",
-- defaults = { lazy = true },
})
EOF
else " f]]
" Plugins for pure vim: f[[
syntax on
filetype off " for vundle
call plug#begin('~/.vim/bundle')
" UI And Basic:
Plug 'vim-scripts/LargeFile'
Plug 'lambdalisue/suda.vim'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'ppwwyyxx/vim-PinyinSearch'
" Window Tools:
Plug 'mbbill/undotree'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'preservim/tagbar'
" Editing Tools:
Plug 'rhysd/accelerated-jk'
Plug 'yonchu/accelerated-smooth-scroll'
Plug 'ojroques/vim-oscyank', {'branch': 'main'}
Plug 'qstrahl/vim-matchmaker'
Plug 'preservim/nerdcommenter'
" Programming:
Plug 'ruanyl/vim-gh-line'
Plug 'derekwyatt/vim-fswitch', {'for': [ 'cpp', 'c' ] }
Plug 'airblade/vim-gitgutter'
Plug 'wakatime/vim-wakatime'
" Syntax:
Plug 'dense-analysis/ale'
call plug#end()
filetype plugin indent on
endif "f]]
" Environment: f[[
if exists('$TMUX') " fix keymap under screen
" tmux will send xterm-style keys when its xterm-keys option is on
exec "set <xUp>=\e[1;*A"
exec "set <xDown>=\e[1;*B"
exec "set <xRight>=\e[1;*C"
exec "set <xLeft>=\e[1;*D"
endif
set shell=zsh
let g:my_term = 'alacritty' " for plugins to open window
set iskeyword+=%,&,?,\|,\\,!
set isfname-==
set grepprg=grep\ -nH\ $*
set t_vb= " shut up bell
set confirm
set shortmess+=s
set fileencodings=ucs-bom,utf8,cp936,big5,euc-jp,euc-kr,gb18130,latin1
set viewoptions=folds,options,cursor,slash,unix
set virtualedit=onemore
scriptencoding utf-8
set ttyfast
"set lazyredraw
" --------------------------------------------------------------------- f]]
" UI: f[[
set title
set titlelen=20
set titlestring=%f
" First load default, then overwrite misc with tokyonight
colo default
if has("nvim")
set termguicolors
hi clear
if has("nvim-0.10")
colo vim
endif
else
" https://github.com/vim/vim/issues/993#issuecomment-255651605
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
set guicursor= " neovim mess up with terminal cursor
if has("nvim")
colo tokyonight-night
set guifont=Monospace:h18
else
set guifont=Monospace\ 16
if has("gui_running") " for gvim/neovide
colo codedark
cnoremap <C-S-v> <C-r>*
endif
endif
set guioptions=aegi " cleaner gui
set t_Co=256
au BufEnter * if &buftype == "quickfix" | syn match Error "error:" | endif
hi Matchmaker guibg=#444444
hi Folded guibg=#444444 guifg=lightblue
hi Search ctermfg=red ctermbg=cyan guibg=#8ca509
hi MatchParen ctermbg=yellow ctermfg=black
hi Visual ctermbg=81 ctermfg=black cterm=NONE guibg=#0a0886 guifg=fg
hi LineNr ctermfg=134 guifg=#d426ff guibg=#24283b
hi VertSplit ctermbg=NONE ctermfg=55 cterm=NONE guifg=#65ec9b
hi PmenuSel guifg=lightgreen
hi Comment ctermfg=blue guifg=#145ecc
hi String ctermfg=13 guifg=#fd26f8
hi Statement ctermfg=3 guifg=#ffff60
hi DiffAdd ctermbg=NONE ctermfg=LightBlue guifg=Green guibg=#2a2a2a
hi DiffDelete guibg=#5a5a5a
hi DiffChange ctermbg=NONE ctermfg=yellow guifg=orange guibg=#2a2a2a
hi DiffText ctermbg=grey ctermfg=red guifg=#df005f guibg=#0a0a0a
hi gitcommitSummary guifg=white
if has('nvim')
" treesitter hlgroups:
hi @variable guifg=white ctermfg=white
hi @field guifg=white ctermfg=white
hi link @variable.builtin Special
hi link @attribute.builtin Special
au FileType python :hi link @constructor @function " cannot distinguish
hi TreesitterContextBottom gui=underdashed guisp=lightgreen
lua << EOF
-- https://github.com/neovim/neovim/issues/14295#issuecomment-950037927
-- looks weird in some terminals
local signs = { Error = "", Warn = "", Hint = "", Info = " " }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
EOF
else
hi clear ALEError
hi clear ALEWarning
endif
" Spell Check:
set spellfile=~/.vim/static/spell.utf-8.add
hi SpellCap guisp=yellow
let g:tex_conceal='adgmb'
set mouse=a
set showcmd " display incomplete commands right_bottom
set numberwidth=1
set relativenumber
set number
set signcolumn=number
set ruler
set rulerformat=%35(%=%r%Y\|%{&ff}\|%{strlen(&fenc)?&fenc:'none'}\ %m\ %l/%L%)
set laststatus=2
set expandtab
set noshowmode
if has('nvim')
set cmdheight=0
au RecordingEnter * set cmdheight=1
au RecordingLeave * set cmdheight=0
lua << END
local theme = require'lualine.themes.powerline_dark'
theme.inactive.c.fg = theme.normal.c.fg
theme.inactive.c.bg = theme.normal.c.bg
local filenamefmt = function(str)
-- shorten the path
local idx = str:find('/google3/')
if idx ~= nil then str = str:sub(idx + 9) end
local parts = vim.split(str, '[\\/]+', {trimempty = true})
for i=1,#parts-2 do
parts[i] = parts[i]:sub(1, 4)
end
return table.concat(parts, "/")
end
require('lualine').setup {
options = {
theme = theme,
component_separators = { left = '', right = ''},
--section_separators = { left = '', right = ''},
section_separators = { left = "", right = "" },
},
sections = {
lualine_a = {{'mode', fmt = function(str) return str:sub(1,1) end }},
lualine_b = {'branch', {'diff', symbols = {added = ' ', modified = ' ', removed = ' '} } },
lualine_c = {
{'filename', shorting_target = 0, path = 1, fmt = filenamefmt, symbols = { modified = ''}, padding={left=0,right=1} },
{'diagnostics', sources = {'nvim_diagnostic', 'ale'}, symbols = { warn = '⚠ '}},
},
lualine_x = {'filetype'}, lualine_y = {}, lualine_z = {{'location', padding = {left=0, right=1}} }
},
inactive_sections = {
lualine_c = {
{'filename', shorting_target = 0, path = 1, fmt = filenamefmt, symbols = { modified = ''} },
},
lualine_x = {'encoding', 'filetype'}, },
extensions = {'nvim-tree', 'trouble'}
}
END
else
let g:airline_theme='durant'
let g:airline_mode_map = {'n': 'N', 'i': 'I', 'R': 'R', 'v': 'V', 'V': 'V'}
let g:airline_left_sep = '»'
let g:airline_right_sep = '«'
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#ale#enabled = 1
endif
set scrolljump=5 " lines to scroll with cursor
set scrolloff=5 " minimum lines to keep at border
set sidescroll=3
set sidescrolloff=3
set nowrap " do not wrap long lines
set whichwrap=b,s,<,>,[,]
set breakat=\ ^I!@*-+;,.?
"set listchars=nbsp:¬,eol:¶,tab:>-,extends:»,precedes:«,trail:•
set fillchars=vert:\|,fold:-,diff:-
if v:version > 703 || has("patch541")
set formatoptions+=nMjm " m: linebreak for Chinese
else
set formatoptions+=nMm
endif
set splitright splitbelow
set backspace=indent,eol,start " allow backspace over everything
set smarttab
set autoindent smartindent
set cino=N-s
set textwidth=0
set tabstop=2 softtabstop=2 shiftwidth=2
set showmatch matchtime=0
set ignorecase smartcase incsearch hlsearch
set magic " for regular expressions
xnoremap / <Esc>/\%V
" use /[^\x00-\x7F] to search multibytes
" ---------------------------------------------------------------------f]]
" History:
set nobackup noswapfile nowritebackup
set history=200 " command line history
if has('persistent_undo')
set undofile " keep an undo record separately for every file
set undolevels=200
if has('nvim')
set undodir=~/.vimtmp/undo
else
set undodir=~/.vimtmp/old_vim_undo
endif
endif
if has('nvim')
set viminfo+=n$HOME/.vimtmp/nviminfo
else
set viminfo+=n$HOME/.vimtmp/viminfo
endif
au CursorHold,CursorHoldI,BufEnter,WinEnter * checktime
set autoread " auto reload file when changes have been detected
set updatetime=500 " time threshold for CursorHold event
" ---------------------------------------------------------------------
" Basic Maps:
set timeoutlen=300 " wait for ambiguous mapping
set ttimeoutlen=0 " wait for xterm key escape
nnoremap ; :
let g:no_viewdoc_maps = 1 " Disable the builtin mapping
command! -bang -nargs=* Q q<bang>
command! -bang -nargs=* -complete=file W w<bang> <args>
command! -bang -nargs=* -complete=file Wq wq<bang> <args>
command! -bang -nargs=* -complete=file WQ wq<bang> <args>
nnoremap <Tab> i<Tab><Esc>
nnoremap <S-Tab> ^i<Tab><Esc>
cnoremap %% <C-R>=expand('%:h').'/'<cr>
if has('nvim')
tnoremap <Esc> <C-\><C-n>
endif
cmap w!! SudaWrite %
cnoremap cd. lcd %:p:h
nnoremap "gf <C-W>gf
" disable ex mode, help and c-a
nnoremap Q <Esc>
nnoremap <F1> <Esc>
inoremap <F1> <Esc>
nnoremap <C-a> <Esc>
vnoremap <CR> <Esc>
vnoremap <expr> I ForceBlockwiseVisual('I')
vnoremap <expr> A ForceBlockwiseVisual('A')
func! ForceBlockwiseVisual(key)
if mode () == 'v'
return "\<C-v>". a:key
elseif mode () == 'V'
return "\<C-v>0o$". a:key
else | return a:key | endif
endfunc
" ---------------------------------------------------------------------
" Clipboard: " + register may be wrong under xterm
nnoremap Y y$
set pastetoggle=<F12> " toggle paste insert mode
au VimEnter * set pastetoggle=<F12> " workaround for bug in neovim #2843
if has("gui_running") || exists('g:neovide') " for gvim/neovide
xnoremap <c-c> "+y
else
vnoremap <C-c> :OSCYankVisual<CR>
endif
inoremap <c-v> <Esc>:set paste<CR>"+p:set nopaste<CR>a
" insert word of the line above
inoremap <C-Y> <C-C>:let @z = @"<CR>mz
\:exec 'normal!' (col('.')==1 && col('$')==1 ? 'k' : 'kl')<CR>
\:exec (col('.')==col('$') - 1 ? 'let @" = @_' : 'normal! yw')<CR>
\`zp:let @" = @z<CR>a
" delete to blackhole register
nnoremap <Del> "_x
vnoremap <Del> "_d
" ---------------------------------------------------------------------
" Folding:
set foldmethod=marker
set foldmarker=f[[,f]]
set foldnestmax=2 " nesting
set foldminlines=5
"set foldcolumn=0
"set diffopt=filler,foldcolumn:0
nnoremap zo zO
" ---------------------------------------------------------------------
" QuickFix:
set switchbuf=split
nnoremap <C-g> <cmd>TroubleClose<CR><cmd>cclose<CR><cmd>pclose<CR>
nnoremap <Leader>xx <cmd>Trouble<CR>
nnoremap ]e :lnext<CR>
nnoremap [e :lprev<CR>
" ---------------------------------------------------------------------
" Cursor Movement: f[[
if isdirectory($HOME . "/.vim/bundle/accelerated-jk") " a variable not assigned
nmap j <Plug>(accelerated_jk_gj)
nmap k <Plug>(accelerated_jk_gk)
endif
let g:accelerated_jk_acceleration_limit = 500
let g:accelerated_jk_acceleration_table = [10, 20, 30, 35, 40, 45, 50]
nnoremap n nzzzv
nnoremap N Nzzzv
inoremap <c-h> <Left>
inoremap <c-j> <Down>
inoremap <c-k> <Up>
inoremap <c-l> <Right>
imap <c-e> <End>
imap <c-a> <Home>
inoremap <c-b> <S-Left>
inoremap <a-f> <Esc>lwi
inoremap <a-b> <Esc>bi
cmap <c-j> <Down>
cmap <c-k> <Up>
cmap <a-f> <S-Right>
cmap <c-b> <S-Left>
cmap <a-b> <S-Left>
cmap <c-e> <End>
cmap <c-a> <Home>
" undoable C-U, C-W
inoremap <c-u> <c-g>u<c-u>
inoremap <c-w> <c-g>u<c-w>
vnoremap << <gv<gv
vnoremap >> >gv>gv
" Save Cursor Position:
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Hint On Moving Cursor
func! HintCursorLine(opr)
if a:opr == 0 " clear cursorline
set nocursorline
if exists("&cc") | set cc= | endif
return
endif
if ! exists('g:last_line') | let g:last_line = -1 | end
if ! exists('g:last_pos') | let g:last_pos = -1 | end
if ! exists('g:last_win') | let g:last_win = -1 | end
let cur_pos = winline()
let cur_line = line(".")
let diff = max([ abs(g:last_line - cur_line), abs(g:last_pos - cur_pos) ])
if g:last_win != winnr() || diff > 3
set cursorline
endif
let g:last_pos = cur_pos
let g:last_line = cur_line
let g:last_win = winnr()
endfunc
"au CursorMoved,BufWinEnter * call HintCursorLine(1) " this greatly affects performance ...
"au CursorHold,CursorHoldI,BufLeave,WinLeave * call HintCursorLine(0)
" Highlight Chosen Columns:
func! ToggleColorColumn(col)
let col_num = (a:col == 0) ? virtcol(".") : a:col
let cc_list = split(&cc, ',')
if count(cc_list, string(col_num)) <= 0
exec "set cc+=".col_num
else
exec "set cc-=".col_num
endif
endfunc
hi ColorColumn ctermbg=red
command ToggleColorColumn call ToggleColorColumn(0)
" ---------------------------------------------------------------------
" Window:
nmap <c-w><Right> 4<c-w>>
nmap <c-w><Left> 4<c-w><
nmap <c-w><Down> 4<c-w>-
nmap <c-w><Up> 4<c-w>+
nmap <c-h> <c-w>h
nmap <c-l> <c-w>l
nmap <c-k> <c-w>k
nmap <c-j> <c-w>j
au vimResized * exe "normal! \<c-w>="
" ---------------------------------------------------------------------f]]
" Auto Fill Brackets:
func! AutoPair(open, close)
let line = getline('.')
if col('.') > strlen(line) || index([' ', ']', ')', '}'], line[col('.') - 1]) > 0
return a:open . a:close . "\<ESC>i"
else
return a:open
endif
endfunc
func! ClosePair(char)
return (getline('.')[col('.') - 1] == a:char ? "\<Right>" : a:char)
endfunc
inoremap <expr> ( AutoPair('(', ')')
inoremap <expr> ) ClosePair(')')
inoremap <expr> [ AutoPair('[', ']')
inoremap <expr> ] ClosePair(']')
inoremap <expr> { AutoPair('{', '}')
inoremap <expr> } ClosePair('}')
inoremap " ""<Left>
inoremap ' ''<Left>
au Filetype mkd,tex,txt,lrc silent! iunmap '
au Filetype vim silent! iunmap "
au Filetype vim silent! iunmap ""
" ---------------------------------------------------------------------
" Pinyin
source $HOME/.vim/chinese.vim
nmap <Leader>ps :call PinyinSearch()<CR>
nnoremap ? :call PinyinSearch()<CR>
nmap <Leader>pn :call PinyinNext()<CR>
let g:PinyinSearch_Dict = $HOME . "/.vim/bundle/vim-PinyinSearch/PinyinSearch.dict"
" Delete Trailing Whitespaces On Saving:
func! DeleteTrailingWhiteSpace()
normal mZ
%s/\s\+$//e
normal `Z
endfunc
command DeleteTrailingWhiteSpace call DeleteTrailingWhiteSpace()
au BufWritePre * call DeleteTrailingWhiteSpace()
" ---------------------------------------------------------------------
" Log For Debugging Vimscript:
func! ToggleVimscriptVerbose()
if !&verbose
exe "!rm /tmp/vimlog"
set verbosefile=/tmp/vimlog
set verbose=10
else | set verbose=0 | set verbosefile= | endif
endfunc
command ToggleVimscriptVerbose call ToggleVimscriptVerbose()<CR>
" ---------------------------------------------------------------------
" Diff Current Buffer With Correspondent Saved File:
func! DiffWithSaved()
let ft=&filetype
diffthis
vnew | r # | normal! 1Gdd
diffthis
exe "setlocal bt=nofile bh=wipe nobl noswf ro ft=" . ft
endfunc
command! DiffWithSaved call DiffWithSaved()
nnoremap <Leader>df :call DiffWithSaved()<CR>
" ---------------------------------------------------------------------
" Misc Functions:
" Copy,Backup,Evening,Nowrap,VirtualEdit,Line,Noh,Sync,pagejoin,pageq
nmap <Leader>cp :!yank % <CR>
nnoremap <Leader>bk :!mkdir -p vim_backup; cp % vim_backup/%_bk --backup=numbered <CR>
nmap <Leader>tw :set wrap!<CR>
nmap <Leader>rd :redraw!<CR>
func! ClearMyHighlight()
" https://vi.stackexchange.com/questions/3148/what-is-the-functional-difference-between-nohlsearch-and-set-nohlsearch
call clearmatches()
return ":let v:hlsearch=0\<CR>:silent! SearchBuffersReset\<CR>"
endfunc
nnoremap <expr> <Leader>no ClearMyHighlight()
" Paragraph join
nnoremap <Leader>pj v}Jj0O
nnoremap <leader>pq gqip
nnoremap <Leader>-- o<C-R>=printf('%s%s', printf(&commentstring, ' '), repeat('-', 90))<CR><Home><Esc>
" change current line to title case
nnoremap <Leader>tc :s/\<\(\w\)\(\w*\)\>/\u\1\L\2/g
" Completetion And Tags: f[[
set wildmenu " command-line completion
set wildmode=list:longest,full
set wildignore+=*.o,main,*.pyc,*.aux,*.toc,*.bin " don't add .class for javacomplete searching for Reflection.class
set wildignore+=*.git,*.svn,*.hg
set wildignore+=*.sqlite3
set wildignore+=*~,*.bak,*.sw,*.gif
set completeopt=menu,menuone,preview,longest
set complete=.,w,b,u
set path+=./include, " path containing included files for searching variables
" Prevent the first completion result to be chosen, only needed for C++?
inoremap <C-O> <C-X><C-O><C-P>
inoremap <C-P> <C-X><C-P>
set dict+=$HOME/.vim/static/dict_with_cases " use c-X c-K to open dictionary completion
set tags=.tags
nmap <Leader>tag :!ctags -R -f .tags --c++-kinds=+p --fields=+iaS --extra=+q . <CR><CR>
let g:clang_format#code_style = 'google'
let g:clang_format#style_options = {
\ "IndentWidth": "4",
\ "TabWidth": "4",
\ "ContinuationIndentWidth": "2",
\ "BinPackParameters": "false",
\ "IndentCaseLabels": "true",
\ "PenaltyExcessCharacter": "1000",
\ "PenaltyReturnTypeOnItsOwnLine": "10",
\ "Cpp11BracedListStyle": "true",
\ "AllowShortIfStatementsOnASingleLine" : "true",
\ "AllowShortLoopOnASingleLine" : "true",
\ "Standard" : "C++11" }
set statusline+=%#warningmsg#
set statusline+=%*
let g:ale_linters_explicit = 1
if has('nvim')
let g:ale_use_neovim_diagnostics_api = 1
endif
let g:ale_linters = {'python': ['flake8'], 'sh': ['shellcheck']}
let g:ale_fixers = {'python': ['black']}
" Only enable hard errors https://flake8.pycqa.org/en/latest/user/error-codes.html
let g:ale_python_flake8_options = '--max-line-length 120 --select F8,F402,F404,F405'
let g:ale_python_black_options = '-l 100'
if has('nvim')
lua << EOF
local cmp = require("cmp")
cmp.setup({
snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) end, },
mapping = cmp.mapping.preset.insert({
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-u>"] = cmp.mapping.scroll_docs(4),
["<C-e>"] = cmp.mapping(function(fallback)
cmp.mapping.close()
fallback()
end, {"i"}),
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
["<CR>"] = cmp.mapping.confirm({ select = false }),
-- https://github.com/zbirenbaum/copilot-cmp#tab-completion-configuration-highly-recommended
["<Tab>"] = vim.schedule_wrap(function(fallback)
local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then return false end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_text(0, line-1, 0, line-1, col, {})[1]:match("^%s*$") == nil
end
if cmp.visible() and has_words_before() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
else
fallback()
end
end),
--["<Tab>"] = cmp.mapping(cmp.mapping.select_next_item(), {"i", "c"}),
}),
sources = {
{ name = "copilot", group_index = 2 },
{ name = "nvim_lsp", group_index = 2 },
{ name = 'nvim_lsp_signature_help', group_index=1 },
{ name = "path", group_index = 3 },
{ name = "buffer", keyword_length = 5, group_index = 3 },
{ name = "nvim_lua", group_index = 3 },
},
window = {
completion = { winhighlight = "Normal:CmpPmenu,FloatBorder:CmpPmenu" },
documentation = { winhighlight = "Normal:CmpPmenu,FloatBorder:CmpPmenu", border = "rounded" }
},
formatting = {
format = require("lspkind").cmp_format({
mode = "symbol",
with_text = true,
maxwidth = 40, -- half max width
menu = {
buffer = "[Buf]", path = "[Path]",
nvim_lsp = "[LSP]", nvim_lua = "[Vim]",
},
}),
},
experimental = { ghost_text = true },
})
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'cmdline', option = { ignore_cmds = { 'Man', '!' } } }
}),
matching = { disallow_fuzzy_matching = true, disallow_partial_matching = true },
completion = { keyword_length = 3 },
formatting = { fields = {'abbr'} },
window = { completion = { border = "rounded" } },
})
cmp.setup.filetype({ 'text', 'help'}, {
sources = {{ name = 'path' }, { name = 'buffer'} }
})
EOF
endif
" ---------------------------------------------------------------------f]]
" Set Title: " TODO for normal type of file f[[
let g:custom_head_list = [" File:"]
func! GenerateHead(line)
call append(a:line, g:custom_head_list)
" comment
normal ggVG cl
silent! exec "%s/^ \\+//g"
endfunc
func! SetTitle()
let file_name = expand("%:t")
let file_head = expand("%:t:r")
if &ft == 'sh'
call setline(1, "!/bin/bash -e")
call GenerateHead(1)
normal G
elseif file_name =~ "^[^.]*\.hh*[px]*$"
call GenerateHead(0)
call append(line("$"), ["#pragma once", ""])
normal G
elseif &ft == 'cpp'
call GenerateHead(0)
call append(line("$"), ["#include <iostream>","#include <cstring>","#include <cstdio>",
\ "#include <limits>","#include <vector>", "#include <unordered_map>", "#include <set>",
\ "#include <iterator>", "#include <unordered_set>", "#include <queue>", "using namespace std;",
\ "#define MSET(ARR, x) memset(ARR, x, sizeof(ARR))",
\ "#define REP(x, y) for (auto x = decltype(y){0}; x < (y); x ++)",
\ "#define REPL(x, y, z) for (auto x = decltype(z){y}; x < (z); x ++)",
\ "#define REPD(x, y, z) for (auto x = decltype(z){y}; x >= (z); x --)",
\ "#define P(a) std::cout << (a) << std::endl",
\ "#define PP(a) std::cout << #a << \": \" << (a) << std::endl",
\ "#define PA(arr) \\", " do { \\", " std::cout << #arr << \": \"; \\",
\ " std::copy(begin(arr), end(arr), std::ostream_iterator<std::remove_reference<decltype(arr)>::type::value_type>(std::cout, \" \")); \\",
\ " std::cout << std::endl; \\",
\ " } while (0)" ])
normal G
elseif &ft == 'ruby'
0put=\"!/usr/bin/env ruby\<nl> coding: utf-8\"
call GenerateHead(2)
normal G
elseif &ft == 'java'
call GenerateHead(0)
call append(line("$"), ["public class ". file_head . " {", "\tpublic static void main(String[] args) {", "\t}", "}"])
normal jjj
elseif &ft == 'tex' || &ft == 'javascript' || &ft == 'coffee'
call GenerateHead(0)
normal G
endif
endfunc
au BufNewFile *.* call SetTitle()
" ---------------------------------------------------------------------f]]
" Make For Programming: f[[
"for gprof
command! -nargs=* Makepg call Make_arg("g++ % -o %:r -pg -Wall -std=c++11", <f-args>)
func! Make() " silent make with quickfix window popup
make
redraw!
for i in getqflist()
if i['valid']
cwin | winc p | return
endif
endfor
endfunc
au Filetype gnuplot let &makeprg="gnuplot % ; feh ./*"
au Filetype dot let &makeprg="dot -Tpng -O -v % ; feh %.png"
au Filetype php let &makeprg="php %"
au Filetype r let &makeprg="R <% --vanilla"
au Filetype sh let &makeprg="shellcheck -f gcc %"
au FileType javascript let &makeprg="node %"
func! InstantRun()
if &ft == 'python' | :!python %
elseif &ft == 'ruby' | :!ruby %
elseif &ft == 'sh' | :!bash %
elseif &ft == 'cpp' | :!gdb %<
elseif &ft == 'java' | :! java %<
elseif &ft == 'javascript' | :! node %
elseif &ft == 'coffee' | :! coffee %
elseif &ft == 'haskell' | :! runhaskell %
else | call Make() | endif
endfunc
nnoremap <Leader>rr :call InstantRun() <CR>
nnoremap <Leader>mk :call Make()<CR>
nnoremap <Leader>mr :!make run <CR>
" --------------------------------------------------------------------- f]]
" ---------------------------------------------------------------------f]]
" Misc FileType Commands:
au BufRead *.conf setf conf
au BufWritePost .Xresources silent !xrdb %
au BufWritePost .tmux.conf silent !tmux source %
au BufWritePost .xbindkeysrc silent !killall -HUP xbindkeys
au BufWritePost *.desktop,mimeapps.list silent !bash -c 'update-mime-database ~/.local/share/mime'
au BufRead tmux.conf,.tmux* setf tmux
au BufRead /usr/include/* setf cpp
au BufRead SConstruct setf python
au BufRead TARGETS,WORKSPACE setf syntax=python | setl expandtab
au BufNewFile,BufRead config.fish set ft=sh " syntax for fish config file
au BufNewFile,BufRead *.json setl ft=json syntax=txt
au BufNewFile,BufRead /tmp/dir*,/tmp/tmp*,/tmp/*edir.sh setf txt | setl ts=4 " for vidir / vimv / edir
au BufWritePost,BufWrite __doc__ setf txt
au BufNewFile,BufRead *.mako setf mako
au BufNewFile,BufRead *.g,*.y,*.ypp setl syntax=antlr3 " syntax for CFG
au BufNewFile,BufRead *.ejs set syntax=html ft=html
au BufNewFile,BufRead *.ispc set syntax=cpp
au BufNewFile,BufRead *.gprof setf gprof
au BufNewFile,BufRead *.txt,*.doc,*.pdf setf txt
au BufNewFile,BufRead *.lrc setf lrc
au BufNewFile,BufRead *.elv setl ft=zsh syntax=zsh
au BufReadPre *.doc,*.class,*.pdf setl ro
au BufReadPost *.doc silent %!antiword "%"
au BufReadPost *.pdf silent %!pdftotext -nopgbrk "%" -
au BufRead *.class exe 'silent %!javap -c "%"' | setf java
au FileType javascript setl ts=2 sw=2 sts=2
au Filetype lrc :match Underlined /.\%45v.\+/
au Filetype lrc setl textwidth=45 " for display in iphone
au FileType json setl foldmethod=syntax
au FileType make setl noexpandtab
au FileType yaml setl foldmethod=indent foldlevel=99 fml=1
au Filetype txt,crontab setl textwidth=500
au FileType sh,zsh inoremap ` ``<Left>
" https://github.com/martinvonz/jj/discussions/2413
au BufRead *.jjdescription
\ syn match jjcommitComment "^JJ: .*$" contains=@NoSpell |
\ hi def link jjcommitComment Comment
au BufWritePost *
\ if getline(1) =~ "^#!/bin/[a-z]*sh" |
\ exe "silent !chmod a+x <afile>" |
\ endif
" ---------------------------------------------------------------------
" Misc Plugins: f[[
" <Leader>mar to mark
" surround: ds/cs in normal mode, s in visual mode
" <Leader>tt to Align latex table
" <Leader>t= <Leader>T= to Align = (left or right)
" <Leader>z/Z/iz to fold/restore/reverse_fold search result
" Tyank, Twrite, Tput to use tbone for tmux
" {count}zS to show highlight