-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.vim
794 lines (691 loc) · 23.8 KB
/
init.vim
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
" *************************************************************************
" presettings
" *************************************************************************
" ASCII art -- https://patorjk.com/software/taag/#p=display&f=Small&t=MY-VIMRC
let MY_VIMRC_WELCOME = "\n"
\ .' __ ____ __ __ _____ __ __ ___ ___ '."\n"
\ .'| \/ \ \ / /_\ \ / /_ _| \/ | _ \/ __|'."\n"
\ .'| |\/| |\ V /___\ V / | || |\/| | / (__ '."\n"
\ .'|_| |_| |_| \_/ |___|_| |_|_|_\\___|'."\n"
" only use basic functions of my-vimrc -- 1:true 0:false
let MY_VIMRC_BASIC = 0
" mirrors for github site & github raw
let GITHUB_SITE = 'https://ghp.ci/https://github.com/'
"let GITHUB_SITE = 'https://www.ghproxy.cn/https://github.com/'
"let GITHUB_SITE = 'https://github.site/'
"let GITHUB_SITE = 'https://github.store/'
"let GITHUB_SITE = 'https://github.com/'
let GITHUB_RAW = 'https://ghp.ci/https://raw.githubusercontent.com/'
"let GITHUB_RAW = 'https://www.ghproxy.cn/https://raw.githubusercontent.com/'
"let GITHUB_RAW = 'https://raw.github.site/'
"let GITHUB_RAW = 'https://raw.github.store/'
"let GITHUB_RAW = 'https://raw.githubusercontent.com/'
" *************************************************************************
" basic settings
" *************************************************************************
" make nvim startup faster
lua vim.loader.enable()
set encoding=utf8
" to enable backspace key
" https://vi.stackexchange.com/a/2163
set backspace=indent,eol,start
set cursorline
set novisualbell
" to deal with REPLACE MODE problem on windows cmd or windows terminal
" https://superuser.com/a/1525060
set t_u7=
set t_Co=256
set hlsearch
set ignorecase
set smartcase
set number
set relativenumber
set nowrap
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set wildmode=longest,full
set wildmenu
set mouse=a
set splitbelow
set dictionary+=/usr/share/dict/words
set complete+=k
set listchars=eol:↵,tab:\|\|,trail:~,extends:>,precedes:<,space:·
set list
" Let's save undo info!
" from https://vi.stackexchange.com/a/53
let s:undo_dir = expand(stdpath("data")."/undo-dir")
if !isdirectory(s:undo_dir)
call mkdir(s:undo_dir, "p", 0700)
endif
let &undodir = s:undo_dir
set undofile
" search tags file recursively
" https://stackoverflow.com/a/5019111/15283141
set tags=./tags,./TAGS,tags;~,TAGS;~
" *************************************************************************
" basic functions
" *************************************************************************
" a wrapper of input() but without the retval
function! s:ShowDialog(text)
if !has('gui_running')
"TODO: a trick only to keep the text shown on win32
if has('win32')
new | redraw | quit
echo "\n"
endif
call input(a:text)
else
call inputdialog(a:text)
endif
endfunction
" verify the first maxline of the downloaded file with the pattern
" retval: 0 -- good;
" -1 -- file not readable;
" -2 -- pattern not found in the first maxline of file
function! s:VerifyDownload(filename, pattern, maxline)
if !filereadable(a:filename)
echo '[my-vimrc] Download failed. "'.a:filename.'" is not found or not readable.'
return -1
endif
let lines = readfile(a:filename)
let line_count = len(lines)
let i = 0
while i < line_count && i < a:maxline
if lines[i] =~ a:pattern
return 0
endif
let i += 1
endwhile
echo '[my-vimrc] Verification failed. "'.a:filename.'" might be corrupted.'
return -2
endfunction
" allow toggling between local and default mode
" https://vim.fandom.com/wiki/Toggle_between_tabs_and_spaces
function! TabToggle()
if &expandtab
set noexpandtab
else
set expandtab
endif
endfunction
" *************************************************************************
" basic filetypes
" *************************************************************************
" scons
augroup scons_ft
au!
autocmd bufnewfile,bufread sconstruct set filetype=python
augroup end
" *************************************************************************
" basic keymaps
" *************************************************************************
" use <Esc> to quit terminal mode
tnoremap <Esc> <C-\><C-n>
" quickly edit this config file
nnoremap <leader>ve :tabnew $MYVIMRC<CR>
" quickly save and source this config file
nnoremap <leader>vs :wa<Bar>so $MYVIMRC<CR>
" toggle list char and indentation mark
nnoremap <leader>l :set list!<Bar>IndentBlanklineToggle<CR>
" toggle paste mode
nnoremap <leader>p :set paste!<CR>
" toggle tab/spaces
nnoremap <leader>t :call TabToggle()<CR>
" auto formatting
nnoremap <leader>f <C-V>gq
vnoremap <leader>f gq
nnoremap <leader>F :lua vim.lsp.buf.format()<CR>
" switch between tabs
nnoremap <leader>} :tabnext<CR>
nnoremap <leader>{ :tabprevious<CR>
" switch between buffers
nnoremap <leader>] :bnext<CR>
nnoremap <leader>[ :bprevious<CR>
" *************************************************************************
" plugin manager
" *************************************************************************
" only use basic functions of my-vimrc
if MY_VIMRC_BASIC != 0
finish
endif
" first we check for git; finish execution if no git is found
if !executable('git')
call s:ShowDialog('[my-vimrc] The "git" command is missing. '
\ .'Only basic functions are available.'
\ ."\nPress ENTER to continue\n")
finish
endif
let AUTOLOAD_DIR = stdpath('config').'/autoload'
let PLUGIN_MANAGER_PATH = expand(AUTOLOAD_DIR.'/plug.vim')
let PLUGIN_MANAGER_URL = GITHUB_RAW.'/junegunn/vim-plug/master/plug.vim'
let PLUGIN_MANAGER_PATTERN = ':PlugInstall'
" download the plugin manager if not installed
silent if s:VerifyDownload(PLUGIN_MANAGER_PATH, PLUGIN_MANAGER_PATTERN, 1000) != 0
" welcome our beloved user
call s:ShowDialog(MY_VIMRC_WELCOME."\n[my-vimrc] Thank you for using my-vimrc!\n"
\ ."Press ENTER to download the plugin manager\n")
" try different ways to download the plugin manager
if has('win32') && executable('powershell')
silent execute '!powershell "iwr -useb '.PLUGIN_MANAGER_URL.' |` '
\ .'ni '.PLUGIN_MANAGER_PATH.' -Force"'
elseif has('win32') && executable('certutil')
silent execute '!(if not exist "'.AUTOLOAD_DIR.'" mkdir "'.AUTOLOAD_DIR.'")'
\ .'&& certutil -urlcache -split -f "'.PLUGIN_MANAGER_URL.'"'
\ .' "'.PLUGIN_MANAGER_PATH.'"'
elseif executable('wget')
silent execute '!mkdir -p '.AUTOLOAD_DIR.' '
\ .'&& wget -O '.PLUGIN_MANAGER_PATH.' '.PLUGIN_MANAGER_URL.' '
\ .'&& echo "Download successful." || echo "Download failed." '
elseif executable('curl')
silent execute '!curl -fLo '.PLUGIN_MANAGER_PATH
\ .' --create-dirs '.PLUGIN_MANAGER_URL.' '
\ .'&& echo "Download successful." || echo "Download failed." '
else
echo '[my-vimrc] No downloader available.'
endif
" verify the downloaded file; finish the execution if failed
if s:VerifyDownload(PLUGIN_MANAGER_PATH, PLUGIN_MANAGER_PATTERN, 1000) != 0
call s:ShowDialog('[my-vimrc] Unable to download the plugin manager. '
\ .'Only basic functions are available. '
\ ."\nPlease manually download the plugin manager from "
\ .'"https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"'
\ .' and save it as "'.PLUGIN_MANAGER_PATH.'"'
\ ."\nPress ENTER to continue\n")
finish
else
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
endif
call plug#begin()
" --------------------
" library for neovim plugins
" --------------------
Plug GITHUB_SITE.'nvim-lua/plenary.nvim'
" --------------------
" color scheme
" --------------------
Plug GITHUB_SITE.'folke/tokyonight.nvim', { 'branch': 'main' }
" --------------------
" mostly used
" --------------------
Plug GITHUB_SITE.'preservim/nerdtree', { 'on': 'NERDTreeToggle' }
Plug GITHUB_SITE.'nvim-lualine/lualine.nvim'
Plug GITHUB_SITE.'akinsho/toggleterm.nvim'
Plug GITHUB_SITE.'mbbill/undotree'
Plug GITHUB_SITE.'preservim/tagbar', { 'on': 'TagbarToggle' }
Plug GITHUB_SITE.'vim-scripts/YankRing.vim'
" finder
Plug GITHUB_SITE.'nvim-telescope/telescope.nvim'
" debugger
Plug GITHUB_SITE.'sakhnik/nvim-gdb', { 'do': ':!./install.sh' }
" --------------------
" more convenience
" --------------------
Plug GITHUB_SITE.'ggandor/leap.nvim'
Plug GITHUB_SITE.'ntpeters/vim-better-whitespace'
Plug GITHUB_SITE.'windwp/nvim-autopairs'
Plug GITHUB_SITE.'kylechui/nvim-surround'
Plug GITHUB_SITE.'notjedi/nvim-rooter.lua'
Plug GITHUB_SITE.'junegunn/vim-peekaboo'
Plug GITHUB_SITE.'terrortylor/nvim-comment'
Plug GITHUB_SITE.'ethanholz/nvim-lastplace'
" system clipboard
Plug GITHUB_SITE.'ojroques/vim-oscyank'
Plug GITHUB_SITE.'christoomey/vim-system-copy'
" git related
Plug GITHUB_SITE.'tpope/vim-fugitive'
Plug GITHUB_SITE.'junegunn/gv.vim'
" neovim performance
Plug GITHUB_SITE.'dstein64/vim-startuptime'
" --------------------
" highlight & appearance
" --------------------
Plug GITHUB_SITE.'nvim-treesitter/nvim-treesitter'
Plug GITHUB_SITE.'p00f/nvim-ts-rainbow'
Plug GITHUB_SITE.'luochen1990/rainbow'
Plug GITHUB_SITE.'nyngwang/murmur.lua'
Plug GITHUB_SITE.'lukas-reineke/indent-blankline.nvim'
Plug GITHUB_SITE.'akinsho/bufferline.nvim'
Plug GITHUB_SITE.'nvim-zh/colorful-winsep.nvim'
" --------------------
" LSP related
" --------------------
Plug GITHUB_SITE.'neovim/nvim-lspconfig' " Collection of configurations for built-in LSP client
Plug GITHUB_SITE.'hrsh7th/nvim-cmp' " Autocompletion plugin
Plug GITHUB_SITE.'hrsh7th/cmp-path'
Plug GITHUB_SITE.'hrsh7th/cmp-nvim-lsp' " LSP source for nvim-cmp
Plug GITHUB_SITE.'saadparwaiz1/cmp_luasnip' " Snippets source for nvim-cmp
Plug GITHUB_SITE.'L3MON4D3/LuaSnip' " Snippets plugin
Plug GITHUB_SITE.'ray-x/lsp_signature.nvim' " Function signature
Plug GITHUB_SITE.'WhoIsSethDaniel/toggle-lsp-diagnostics.nvim' " Toggle LSP diagnostics
call plug#end()
" *************************************************************************
" Language Server Protocol (LSP) server configs
" *************************************************************************
" [neovim/nvim-lspconfig]
" https://github.com/neovim/nvim-lspconfig
lua << EOF
-- register your installed LSP server here
MY_LSP_SERVER_LIST = {
-- for example:
-- "pylsp",
-- "clangd",
}
-- find out LSP server for each language :
-- https://github.com/williamboman/nvim-lsp-installer#available-lsps
-- my custom config function,
-- only take effect on buffers with an active language server
MY_CUSTOM_ON_ATTACH = function(client)
-- hotkeys for LSP service
vim.keymap.set('n','gD','<cmd>lua vim.lsp.buf.declaration()<CR>')
vim.keymap.set('n','gd','<cmd>lua vim.lsp.buf.definition()<CR>')
vim.keymap.set('n','K','<cmd>lua vim.lsp.buf.hover()<CR>')
vim.keymap.set('n','gr','<cmd>lua vim.lsp.buf.references()<CR>')
vim.keymap.set('n','gs','<cmd>lua vim.lsp.buf.signature_help()<CR>')
vim.keymap.set('n','gi','<cmd>lua vim.lsp.buf.implementation()<CR>')
vim.keymap.set('n','gt','<cmd>lua vim.lsp.buf.type_definition()<CR>')
end
EOF
" *************************************************************************
" plugin configs
" *************************************************************************
" [folke/tokyonight.nvim]
lua << EOF
require("tokyonight").setup({
style = "night",
light_style = "day",
transparent = false,
terminal_colors = true,
})
EOF
colorscheme tokyonight
" [preservim/nerdtree]
let NERDTreeWinPos="right"
let NERDTreeShowHidden=1
let NERDTreeMouseMode=2
" disable the original file explorer
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
" lazy load nerdtree when open a directory
" https://github.com/junegunn/vim-plug/issues/424#issuecomment-189343357
augroup nerd_loader
autocmd!
autocmd VimEnter * silent! autocmd! FileExplorer
autocmd BufEnter,BufNew *
\ if isdirectory(expand('<amatch>'))
\| call plug#load('nerdtree')
\| execute 'autocmd! nerd_loader'
\| endif
augroup END
" [akinsho/toggleterm.nvim]
" https://github.com/akinsho/toggleterm.nvim
lua << EOF
require("toggleterm").setup{
on_open = function()
if vim.fn.has 'win32' == 1 then
vim.cmd([[startinsert]])
end
end,
}
EOF
" [preservim/tagbar]
let g:tagbar_position = 'vertical leftabove'
let g:tagbar_width = max([25, winwidth(0) / 5])
" [nvim-lualine/lualine.nvim]
lua << END
require('lualine').setup{
options = {
theme = 'auto',
section_separators = '',
component_separators = '|',
icons_enabled = false
}
}
END
" [vim-scripts/YankRing.vim]
" make it compatible for neovim
" https://github.com/neovim/neovim/issues/2642#issuecomment-218232937
let g:clipboard = {} " https://github.com/neovim/neovim/issues/9570
let g:yankring_clipboard_monitor = 0
" to avoid <C-p> collision with the ctrlp plugin
let g:yankring_replace_n_pkey = '<m-p>'
let g:yankring_replace_n_nkey = '<m-n>'
" save yankring history in this dir
let yankring_path=expand(stdpath("data")."/yankring-dir")
if !isdirectory(yankring_path)
call mkdir(yankring_path, "p", 0700)
endif
let g:yankring_history_dir = yankring_path
" [nvim-telescope/telescope.nvim]
lua << EOF
-- https://www.reddit.com/r/neovim/comments/pzxw8h/telescope_quit_on_first_single_esc/
local actions = require("telescope.actions")
require('telescope').setup{
defaults = {
mappings = {
n = {
["<F9>"] = actions.close,
},
i = {
["<F9>"] = actions.close,
["<RightMouse>"] = actions.close,
["<LeftMouse>"] = actions.select_default,
["<ScrollWheelDown>"] = actions.move_selection_next,
["<ScrollWheelUp>"] = actions.move_selection_previous,
},
},
},
}
EOF
" [sakhnik/nvim-gdb]
" https://github.com/sakhnik/nvim-gdb
" disable default keymaps
let g:nvimgdb_disable_start_keymaps = 1
" set debugger keymaps
function! NvimGdbNoTKeymaps()
tnoremap <silent> <buffer> <esc> <c-\><c-n>G
endfunction
nnoremap <M-r> :GdbRun<CR>
let g:nvimgdb_config_override = {
\ 'key_next': '<M-n>',
\ 'key_step': '<M-s>',
\ 'key_finish': '<M-f>',
\ 'key_continue': '<M-c>',
\ 'key_until': '<M-t>',
\ 'key_breakpoint': '<M-b>',
\ 'key_quit': '<M-q>',
\ 'key_eval': '<M-e>',
\ 'set_tkeymaps': "NvimGdbNoTKeymaps",
\ }
" [ggandor/leap.nvim]
lua << EOF
require('leap').add_default_mappings()
EOF
" [ntpeters/vim-better-whitespace]
" https://github.com/ntpeters/vim-better-whitespace/issues/158
augroup vimrc
autocmd TermOpen * :DisableWhitespace
augroup END
" [windwp/nvim-autopairs] with nvim-cmp
" https://github.com/windwp/nvim-autopairs
lua << EOF
require("nvim-autopairs").setup {}
-- If you want insert `(` after select function or method item
local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local cmp = require('cmp')
cmp.event:on(
'confirm_done',
cmp_autopairs.on_confirm_done()
)
EOF
" [kylechui/nvim-surround]
lua << EOF
require("nvim-surround").setup()
EOF
" [notjedi/nvim-rooter.lua]
lua << EOF
require'nvim-rooter'.setup()
EOF
" [terrortylor/nvim-comment]
lua << EOF
require('nvim_comment').setup({
comment_empty = false
})
EOF
" [ethanholz/nvim-lastplace]
lua << EOF
require'nvim-lastplace'.setup {
lastplace_ignore_buftype = {"quickfix", "nofile", "help"},
lastplace_ignore_filetype = {"gitcommit", "gitrebase", "svn", "hgcommit"},
lastplace_open_folds = true
}
EOF
" [christoomey/vim-system-copy]
let g:system_copy_enable_osc52 = 1
if has('win32') && executable('powershell')
" force cmd.exe to use utf-8 encoding
" https://stackoverflow.com/questions/57131654/using-utf-8-encoding-chcp-65001-in-command-prompt-windows-powershell-window
call system('chcp 65001')
" https://github.com/christoomey/vim-system-copy/pull/35#issue-557371087
let g:system_copy#paste_command='powershell "Get-Clipboard"'
endif
" [nvim-treesitter/nvim-treesitter]
lua << EOF
for _, config in pairs(require("nvim-treesitter.parsers").get_parser_configs()) do
config.install_info.url = config.install_info.url:gsub("^https://github.com/", vim.api.nvim_get_var('GITHUB_SITE'))
end
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
-- [p00f/nvim-ts-rainbow]
rainbow = {
enable = true,
extended_mode = true,
},
}
EOF
" [nyngwang/murmur.lua]
lua << EOF
require('murmur').setup {
max_len = 80,
min_len = 1,
}
EOF
" [rainbow/luochen1990]
let g:rainbow_active = 1
let g:rainbow_conf = {
\ 'separately': {
\ 'nerdtree': 0,
\ }
\}
" [lukas-reineke/indent-blankline.nvim]
" https://github.com/lukas-reineke/indent-blankline.nvim
lua << EOF
require("ibl").setup()
EOF
" [akinsho/bufferline.nvim]
" https://github.com/akinsho/bufferline.nvim
lua << EOF
require("bufferline").setup{
options = {
mode = "buffers",
show_buffer_icons = false,
buffer_close_icon = 'x',
close_icon = 'X',
left_trunc_marker = '',
right_trunc_marker = '',
offsets = {
{
filetype = "nerdtree",
text = "File Explorer",
highlight = "Directory",
separator = true
},
{
filetype = "undotree",
text = "Undo History",
highlight = "Directory",
separator = true
},
{
filetype = "tagbar",
text = "Tag List",
highlight = "Directory",
separator = true
},
},
},
}
EOF
" [nvim-zh/colorful-winsep.nvim]
" https://github.com/nvim-zh/colorful-winsep.nvim
lua << EOF
require('colorful-winsep').setup({
symbols = {"─", "│", "┌", "┐", "└", "┘"},
})
EOF
" [neovim/nvim-lspconfig] auto-completion settings
" https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion
lua << EOF
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
local lspconfig = require('lspconfig')
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
for _, lsp in ipairs(MY_LSP_SERVER_LIST) do
lspconfig[lsp].setup {
on_attach = MY_CUSTOM_ON_ATTACH,
capabilities = capabilities,
}
end
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
-- prefer the traditional autocomplete keymaps
mapping = cmp.mapping.preset.insert({
-- ['<C-d>'] = cmp.mapping.scroll_docs(-4),
-- ['<C-f>'] = cmp.mapping.scroll_docs(4),
-- ['<C-Space>'] = cmp.mapping.complete(),
-- ['<CR>'] = cmp.mapping.confirm {
-- behavior = cmp.ConfirmBehavior.Replace,
-- select = true,
-- },
['<C-n>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<C-p>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
{ name = 'path' },
},
}
EOF
" [ray-x/lsp_signature.nvim]
" https://github.com/ray-x/lsp_signature.nvim
lua << EOF
require "lsp_signature".setup {}
EOF
" [WhoIsSethDaniel/toggle-lsp-diagnostics.nvim]
" https://github.com/WhoIsSethDaniel/toggle-lsp-diagnostics.nvim
lua << EOF
-- turn off lsp diagnostics by default
require'toggle_lsp_diagnostics'.init({ start_on = false })
EOF
" *************************************************************************
" extra functions
" *************************************************************************
" my wrapper for [sakhnik/nvim-gdb]
function! GdbStartAuto()
let current_file_path = expand('%:p')
let current_file_type = &filetype
let debugger_info = [
\ {'name':'gdb', 'filetype':['cpp','c','objcpp'], 'cmd':'GdbStart gdb -q'},
\ {'name':'lldb', 'filetype':['cpp','c','objcpp'], 'cmd':'GdbStartLLDB lldb'},
\ {'name':'pdb', 'filetype':['python'], 'cmd':'GdbStartPDB python3 -m pdb '.current_file_path},
\ {'name':'bashdb', 'filetype':['sh'], 'cmd':'GdbStartBashDB bashdb '.current_file_path},
\ ]
" first try to open the related debugger by current filetype
let counter = 0
for debugger in debugger_info
if index(debugger['filetype'], current_file_type) >= 0
exec(debugger['cmd'])
break
else
let counter += 1
endif
endfor
" if no suitable debugger for the filetype,
" let the user decide which debugger to use
if counter >= len(debugger_info)
echo 'Available debuggers:'
let debugger_number = 1
for debugger in debugger_info
echo ' '.string(debugger_number).'.'.debugger['name'].' '
let debugger_number += 1
endfor
echo ' '.string(debugger_number).'.quit'
"let choosen_number = input('Select a debugger: ')
" save one keystroke by using getchar() instead of input()
" TODO: assert len(debugger_info) < 9 when use getchar()
echo 'Select a debugger:'
let choosen_number = nr2char(getchar())
let idx = choosen_number - 1
redraw " flush the old output
if idx >= 0 && idx < len(debugger_info)
exec(debugger_info[idx]['cmd'])
else
echo 'quit'
endif
endif
endfunction
" *************************************************************************
" extra keymaps
" *************************************************************************
" functional hotkeys for plugins
nnoremap <silent> <F2> :NERDTreeToggle<CR>
nnoremap <silent> <F3> <Cmd>exe v:count1 . "ToggleTerm"<CR>
nnoremap <silent> <F4> :UndotreeToggle<CR>
nnoremap <silent> <F6> :call GdbStartAuto()<CR>
nnoremap <silent> <F7> :YRShow<CR>
nnoremap <silent> <F8> :TagbarToggle<CR>
nnoremap <silent> <F9> :Telescope find_files<CR>
inoremap <silent> <F2> <Esc>:NvimTreeToggle<CR>
inoremap <silent> <F3> <Esc><Cmd>exe v:count1 . "ToggleTerm"<CR>
inoremap <silent> <F4> <Esc>:UndotreeToggle<CR>
inoremap <silent> <F6> <Esc>:call GdbStartAuto()<CR>
inoremap <silent> <F7> <Esc>:YRShow<CR>
inoremap <silent> <F8> <Esc>:TagbarToggle<CR>
cnoremap <silent> <F6> <C-c>
tnoremap <silent> <F3> <C-\><C-n><Cmd>exe v:count1 . "ToggleTerm"<CR>
" plugin manager shortcuts
nnoremap <leader>vi :wa<Bar>silent! so $MYVIMRC<CR>:PlugInstall<CR>
nnoremap <leader>vc :wa<Bar>silent! so $MYVIMRC<CR>:PlugClean<CR>
nnoremap <leader>vu :wa<Bar>silent! so $MYVIMRC<CR>:PlugUpdate<CR>
" test vim startup time
nnoremap <leader>vt :StartupTime --tries 10<CR>
nnoremap <leader>vT :StartupTime --tries 10 --no-sort<CR>
" strip trailing whitespaces
nnoremap <leader>s :StripWhitespace<CR>
" search the word under the cursor
nnoremap <leader>a :Telescope grep_string<CR>
" search the given word
nnoremap <leader>A :Telescope live_grep<CR>
" toggle LSP diagnostics
nnoremap <leader>d :ToggleDiag<CR>
" toggle pwd between the repo's root and the dir of current file
nnoremap <leader>r :RooterToggle<CR>
" christoomey/vim-system-copy
nmap cy <Plug>SystemCopy
xmap cy <Plug>SystemCopy
nmap cY <Plug>SystemCopyLine
nmap cp <Plug>SystemPaste
xmap cp <Plug>SystemPaste
nmap cP <Plug>SystemPasteLine