diff options
-rw-r--r-- | .vim/after/plugin/cmp.vim | 61 | ||||
-rw-r--r-- | .vim/after/plugin/lsp.vim | 6 | ||||
-rw-r--r-- | .vim/after/plugin/minpac.vim | 15 | ||||
-rw-r--r-- | .vim/after/plugin/mucomplete.vim | 4 | ||||
-rw-r--r-- | .vim/after/plugin/nvim-lsp.vim | 59 | ||||
-rw-r--r-- | .vim/after/plugin/treesitter.vim | 20 | ||||
-rw-r--r-- | .vimrc | 25 |
7 files changed, 183 insertions, 7 deletions
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 <silent><expr> <TAB> pumvisible() ? "\<C-n>" : "\<TAB>" +inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" + +packadd nvim-cmp +packadd cmp-buffer +packadd cmp-path +packadd cmp-cmdline + +lua <<EOF + +local cmp = require 'cmp' + +cmp.setup({ + preselect = cmp.PreselectMode.None, + + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + }, { + { name = 'buffer' }, + }), + + mapping = cmp.mapping.preset.insert({ + ['<Tab>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, { 'i', 's' }), + + ['<S-Tab>'] = 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 <<EOF + +local lspconfig = require 'lspconfig' +local cmp_nvim_lsp = require 'cmp_nvim_lsp' + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = cmp_nvim_lsp.update_capabilities(capabilities) + +local opts = { noremap = true, silent = true } + +vim.keymap.set('n', '[g', vim.diagnostic.goto_prev, opts) +vim.keymap.set('n', ']g', vim.diagnostic.goto_next, opts) + +local on_attach = function(client, bufnr) + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + vim.api.nvim_buf_set_option(bufnr, 'tagfunc', 'v:lua.vim.lsp.tagfunc') + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap=true, silent=true, buffer=bufnr } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) + vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) + -- vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts) + -- vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts) + -- vim.keymap.set('n', '<space>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', '<leader>rn', vim.lsp.buf.rename, bufopts) + -- vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + -- vim.keymap.set('n', '<space>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 <<EOF + +local treesitter_config = require 'nvim-treesitter.configs' + +treesitter_config.setup { + ensure_installed = { 'c', 'lua', 'gdscript', 'go', 'python' }, + sync_install = false, + + highlight = { + enable = true, + }, +} + +EOF @@ -28,6 +28,13 @@ if has('python3') elseif has('python') endif +if has('nvim') + set packpath^=~/.vim + set packpath+=~/.vim/after + set runtimepath^=~/.vim + set runtimepath+=~/.vim/after +endif + " GUI set guioptions-=m @@ -43,8 +50,11 @@ set nofoldenable set hidden -set completeopt=menu,menuone,popup,noinsert,noselect -set completepopup=align:menu,border:off,highlight:WildMenu +set completeopt=menu,menuone,noinsert,noselect +if !has('nvim') + set completeopt+=popup + set completepopup=align:menu,border:off,highlight:WildMenu +endif set shortmess+=c set belloff+=ctrlg @@ -52,10 +62,15 @@ set belloff+=ctrlg set diffopt+=followwrap,algorithm:patience " undo -if !isdirectory(expand('~/.vim/.undo')) - silent! call mkdir(expand('~/.vim/.undo', 'p')) +let s:undodir = expand('~/.vim/.undo') +if has('nvim') + " The undo file of vim and nvim is not compatible + let s:undodir = expand('~/.vim/.undo/nvim') +endif +if !isdirectory(expand(s:undodir)) + silent! call mkdir(expand(s:undodir, 'p')) endif -set undodir=~/.vim/.undo// +let &undodir=s:undodir set undofile " set Vim-specific sequences for RGB colors |