From ca6da1729156f74bb36ba94a864ab5e39e78ae3b Mon Sep 17 00:00:00 2001 From: Guangxiong Lin Date: Sat, 4 Jun 2022 16:53:35 +0800 Subject: Try using nvim --- .vim/after/plugin/cmp.vim | 61 ++++++++++++++++++++++++++++++++++++++++ .vim/after/plugin/lsp.vim | 6 ++++ .vim/after/plugin/minpac.vim | 15 ++++++++-- .vim/after/plugin/mucomplete.vim | 4 +++ .vim/after/plugin/nvim-lsp.vim | 59 ++++++++++++++++++++++++++++++++++++++ .vim/after/plugin/treesitter.vim | 20 +++++++++++++ .vimrc | 25 ++++++++++++---- 7 files changed, 183 insertions(+), 7 deletions(-) create mode 100644 .vim/after/plugin/cmp.vim create mode 100644 .vim/after/plugin/nvim-lsp.vim create mode 100644 .vim/after/plugin/treesitter.vim diff --git a/.vim/after/plugin/cmp.vim b/.vim/after/plugin/cmp.vim new file mode 100644 index 0000000..226f8c5 --- /dev/null +++ b/.vim/after/plugin/cmp.vim @@ -0,0 +1,61 @@ +if !has('nvim') + finish +endif + +inoremap pumvisible() ? "\" : "\" +inoremap pumvisible() ? "\" : "\" + +packadd nvim-cmp +packadd cmp-buffer +packadd cmp-path +packadd cmp-cmdline + +lua <'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, { 'i', 's' }), + + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { 'i', 's' }), + }), +}) + +cmp.setup.cmdline('/', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'buffer' }, + }), +}) + +cmp.setup.cmdline(':', { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = 'path' }, + }, { + { name = 'cmdline' }, + }), +}) + +EOF diff --git a/.vim/after/plugin/lsp.vim b/.vim/after/plugin/lsp.vim index fe36f12..07ca6aa 100644 --- a/.vim/after/plugin/lsp.vim +++ b/.vim/after/plugin/lsp.vim @@ -1,6 +1,12 @@ +if has('nvim') + finish +endif + let g:lsp_diagnostics_enabled = 0 let g:lsp_document_code_action_signs_enabled = 0 +packadd vim-lsp + if executable('pylsp') au User lsp_setup call lsp#register_server({ \ 'name': 'pylsp', diff --git a/.vim/after/plugin/minpac.vim b/.vim/after/plugin/minpac.vim index 688c132..baaac09 100644 --- a/.vim/after/plugin/minpac.vim +++ b/.vim/after/plugin/minpac.vim @@ -19,12 +19,23 @@ function! InitMinpac() abort call minpac#add('https://github.com/dense-analysis/ale.git', {'type': 'opt'}) call minpac#add('https://github.com/SirVer/ultisnips.git', {'type': 'opt'}) call minpac#add('https://github.com/honza/vim-snippets') - call minpac#add('https://github.com/prabirshrestha/vim-lsp') + call minpac#add('https://github.com/prabirshrestha/vim-lsp', {'type': 'opt'}) call minpac#add('https://github.com/ctrlpvim/ctrlp.vim.git', {'type': 'opt'}) call minpac#add('https://github.com/FelikZ/ctrlp-py-matcher.git', {'type': 'opt'}) call minpac#add('https://github.com/preservim/tagbar.git') - call minpac#add('https://github.com/ludovicchabant/vim-gutentags.git') + call minpac#add('https://github.com/neovim/nvim-lspconfig', {'type': 'opt'}) + call minpac#add('https://github.com/hrsh7th/nvim-cmp', {'type': 'opt'}) + call minpac#add('https://github.com/hrsh7th/cmp-buffer', {'type': 'opt'}) + call minpac#add('https://github.com/hrsh7th/cmp-path', {'type': 'opt'}) + call minpac#add('https://github.com/hrsh7th/cmp-nvim-lsp', {'type': 'opt'}) + call minpac#add('https://github.com/hrsh7th/cmp-cmdline', {'type': 'opt'}) + call minpac#add('https://github.com/nvim-treesitter/nvim-treesitter', { + \ 'type': 'opt', + \ 'do': 'if has("nvim") | packadd nvim-treesitter | :TSUpdate | endif', + \ }) + + call minpac#add('https://github.com/ludovicchabant/vim-gutentags.git', {'type': 'opt'}) call minpac#add('https://github.com/easymotion/vim-easymotion.git') call minpac#add('https://github.com/airblade/vim-rooter.git') call minpac#add('https://github.com/mbbill/undotree.git') diff --git a/.vim/after/plugin/mucomplete.vim b/.vim/after/plugin/mucomplete.vim index 2e5892e..81751ba 100644 --- a/.vim/after/plugin/mucomplete.vim +++ b/.vim/after/plugin/mucomplete.vim @@ -1,3 +1,7 @@ +if has('nvim') + finish +endif + let g:mucomplete#enable_auto_at_startup = 1 let g:mucomplete#minimum_prefix_length = 1 let g:mucomplete#empty_text_auto = 1 diff --git a/.vim/after/plugin/nvim-lsp.vim b/.vim/after/plugin/nvim-lsp.vim new file mode 100644 index 0000000..f6d23c3 --- /dev/null +++ b/.vim/after/plugin/nvim-lsp.vim @@ -0,0 +1,59 @@ +if !has('nvim') + finish +endif + +packadd nvim-lspconfig +packadd cmp-nvim-lsp + +lua <', vim.lsp.buf.signature_help, bufopts) + -- vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, bufopts) + -- vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, bufopts) + -- vim.keymap.set('n', 'wl', function() + -- print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + -- end, bufopts) + vim.keymap.set('n', 'gy', vim.lsp.buf.type_definition, bufopts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, bufopts) + -- vim.keymap.set('n', 'ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + -- vim.keymap.set('n', 'f', vim.lsp.buf.formatting, bufopts) + + vim.cmd [[ + autocmd! BufWritePre *.go,*.rs lua vim.lsp.buf.formatting_sync(nil, 1000) + ]] + +end + +local servers = { 'clangd', 'gopls' , 'gdscript', 'pylsp' } + +for _, lsp in pairs(servers) do + lspconfig[lsp].setup{ + on_attach = on_attach, + capabilities = capabilities, + } +end + +EOF diff --git a/.vim/after/plugin/treesitter.vim b/.vim/after/plugin/treesitter.vim new file mode 100644 index 0000000..c022662 --- /dev/null +++ b/.vim/after/plugin/treesitter.vim @@ -0,0 +1,20 @@ +if !has('nvim') + finish +endif + +packadd nvim-treesitter + +lua <