From 58d7223925316d78cde1f3bd07b8439f55dabba0 Mon Sep 17 00:00:00 2001 From: Daniel Lynn Date: Fri, 11 Mar 2022 15:49:48 -0600 Subject: [PATCH] Update plugin setup --- nvim/lspconfig.vimrc | 33 +++++++------ nvim/nvim-cmp.vimrc | 109 +++++++++++++++++++++++----------------- nvim/plugins.vimrc | 44 +++++++++-------- vimrc | 115 ++++++++++++++++++++++++------------------- 4 files changed, 168 insertions(+), 133 deletions(-) diff --git a/nvim/lspconfig.vimrc b/nvim/lspconfig.vimrc index 8d84abe..fb72570 100644 --- a/nvim/lspconfig.vimrc +++ b/nvim/lspconfig.vimrc @@ -9,33 +9,34 @@ vim.api.nvim_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.setloclist -- Use an on_attach function to only map the following keys -- after the language server attaches to the current buffer -local on_attach = function(client, bufnr) - +local on_attach = function(_, bufnr) -- Enable completion triggered by - vim.api.nvim_buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') -- See `:help vim.lsp.*` for documentation on any of the below functions - vim.api.nvim_buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - vim.api.nvim_buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.api.nvim_buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) - vim.api.nvim_buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - vim.api.nvim_buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) - vim.api.nvim_buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) - vim.api.nvim_buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) - vim.api.nvim_buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) - vim.api.nvim_buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) - vim.api.nvim_buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) - vim.api.nvim_buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - vim.api.nvim_buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) - vim.api.nvim_buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'f', 'lua vim.lsp.buf.formatting()', opts) end -- Use a loop to conveniently call 'setup' on multiple servers and -- map buffer local keybindings when the language server attaches local servers = { 'solargraph', 'rust_analyzer', 'gopls', 'tsserver', 'stylelint_lsp' } +local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()) for _, lsp in pairs(servers) do nvim_lsp[lsp].setup { on_attach = on_attach, + capabilities = capabilities, flags = { debounce_text_changes = 150, } diff --git a/nvim/nvim-cmp.vimrc b/nvim/nvim-cmp.vimrc index 41d60ce..42851b0 100644 --- a/nvim/nvim-cmp.vimrc +++ b/nvim/nvim-cmp.vimrc @@ -22,50 +22,71 @@ nmap S (vsnip-cut-text) xmap S (vsnip-cut-text) lua <'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), - [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), - [''] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), - [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.close(), - [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }), - [''] = cmp.mapping.confirm({ - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }) - }, - sources = { - { name = 'nvim_lsp' }, - - -- For vsnip user. - { name = 'vsnip' }, - - -- For luasnip user. - -- { name = 'luasnip' }, - - -- For ultisnips user. - -- { name = 'ultisnips' }, - - { name = 'buffer' }, - } +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. + -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. + end, + }, + mapping = { + [''] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }), + [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }), + [''] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), + [''] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), + [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }), + [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), + [''] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [''] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = true, -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }) + }, + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'vsnip' }, -- For vsnip users. + -- { name = 'luasnip' }, -- For luasnip users. + -- { name = 'ultisnips' }, -- For ultisnips users. + -- { name = 'snippy' }, -- For snippy users. + }, { + { name = 'buffer' }, }) +}) + +-- Set configuration for specific filetype. +cmp.setup.filetype('gitcommit', { + sources = cmp.config.sources({ + { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. + }, { + { name = 'buffer' }, + }) +}) + +-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline('/', { + sources = { + { name = 'buffer' } + } +}) + +-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) +}) EOF diff --git a/nvim/plugins.vimrc b/nvim/plugins.vimrc index 89879be..b077384 100644 --- a/nvim/plugins.vimrc +++ b/nvim/plugins.vimrc @@ -8,7 +8,7 @@ Plug 'lukas-reineke/indent-blankline.nvim' Plug 'mfussenegger/nvim-dap' Plug 'nvim-lua/plenary.nvim' Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} -Plug 'petertriho/nvim-scrollbar' +"Plug 'petertriho/nvim-scrollbar' Plug 'posva/vim-vue', { 'for': 'vue' } Plug 'ron-rs/ron.vim', { 'for': 'ron' } Plug 'simrat39/rust-tools.nvim' @@ -23,13 +23,15 @@ Plug 'wakatime/vim-wakatime' Plug 'windwp/nvim-autopairs' " LSP and autocomplete -Plug 'neovim/nvim-lspconfig' | - \ Plug 'hrsh7th/cmp-nvim-lsp' | - \ Plug 'hrsh7th/cmp-buffer' | - \ Plug 'hrsh7th/nvim-cmp' | - \ Plug 'hrsh7th/cmp-vsnip' | - \ Plug 'hrsh7th/vim-vsnip' | - \ Plug 'rafamadriz/friendly-snippets' +Plug 'neovim/nvim-lspconfig' + Plug 'hrsh7th/cmp-nvim-lsp' + Plug 'hrsh7th/cmp-buffer' + Plug 'hrsh7th/cmp-path' + Plug 'hrsh7th/cmp-cmdline' + Plug 'hrsh7th/nvim-cmp' + Plug 'hrsh7th/cmp-vsnip' + Plug 'hrsh7th/vim-vsnip' + Plug 'rafamadriz/friendly-snippets' " Gitsigns Plug 'lewis6991/gitsigns.nvim' @@ -38,24 +40,24 @@ Plug 'lewis6991/gitsigns.nvim' Plug 'nvim-telescope/telescope.nvim' " Lightline -Plug 'itchyny/lightline.vim' | - \ Plug 'albertomontesg/lightline-asyncrun' | - \ Plug 'itchyny/vim-gitbranch' | - \ Plug 'macthecadillac/lightline-gitdiff' | - \ Plug 'ryanoasis/vim-devicons' | - \ Plug 'anstadnik/tmuxline.vim' +Plug 'itchyny/lightline.vim' + Plug 'albertomontesg/lightline-asyncrun' + Plug 'itchyny/vim-gitbranch' + Plug 'macthecadillac/lightline-gitdiff' + Plug 'ryanoasis/vim-devicons' + Plug 'anstadnik/tmuxline.vim' " Using the above fork for lightline truecolor support " \ Plug 'edkolev/tmuxline.vim' " NvimTree -Plug 'kyazdani42/nvim-tree.lua' | - \ Plug 'kyazdani42/nvim-web-devicons' +Plug 'kyazdani42/nvim-tree.lua' + Plug 'kyazdani42/nvim-web-devicons' " Vim-Markdown -Plug 'godlygeek/tabular' | - \ Plug 'plasticboy/vim-markdown', { 'for': 'markdown' } +Plug 'godlygeek/tabular' + Plug 'plasticboy/vim-markdown', { 'for': 'markdown' } " sonokai colorscheme + supporting plugins -Plug 'sainnhe/sonokai' | - \ Plug 'rmolin88/pomodoro.vim' | - \ Plug 'sainnhe/artify.vim' +Plug 'sainnhe/sonokai' + Plug 'rmolin88/pomodoro.vim' + Plug 'sainnhe/artify.vim' diff --git a/vimrc b/vimrc index 7090437..fe0eb02 100644 --- a/vimrc +++ b/vimrc @@ -61,100 +61,111 @@ if executable('rg') set grepprg=rg\ --color\ never endif +" Install vim-plug if not found +if empty(glob('~/.vim/autoload/plug.vim')) + silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs + \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim +endif + " Plugins call plug#begin('~/.vim/plugged') if filereadable(expand("~/.config/nvim/plugins.vimrc")) source ~/.config/nvim/plugins.vimrc + + " Run PlugInstall if there are missing plugins + autocmd VimEnter * if len(filter(values(g:plugs), '!isdirectory(v:val.dir)')) + \| PlugInstall --sync | source ~/.config/nvim/plugins.vimrc + \| endif endif call plug#end() -" Autocomplete -if filereadable(expand("~/.config/nvim/nvim-cmp.vimrc")) - source ~/.config/nvim/nvim-cmp.vimrc -endif - -" Autopairs -if filereadable(expand("~/.config/nvim/autopairs.vimrc")) - source ~/.config/nvim/autopairs.vimrc -endif - -" LSP -if filereadable(expand("~/.config/nvim/lspconfig.vimrc")) - source ~/.config/nvim/lspconfig.vimrc -endif - " Keybindings if filereadable(expand("~/.config/nvim/keybindings.vimrc")) source ~/.config/nvim/keybindings.vimrc endif -" Gitsigns setup -if filereadable(expand("~/.config/nvim/gitsigns.vimrc")) - source ~/.config/nvim/gitsigns.vimrc -endif - -" Telescope setup -if filereadable(expand("~/.config/nvim/telescope.vimrc")) - source ~/.config/nvim/telescope.vimrc -endif - -" Search -if filereadable(expand("~/.config/nvim/hlslens.vimrc")) - source ~/.config/nvim/hlslens.vimrc -endif - -" Lightline setup -if filereadable(expand("~/.config/nvim/lightline.vimrc")) - source ~/.config/nvim/lightline.vimrc -endif - -" Tmuxline setup -if filereadable(expand("~/.config/nvim/tmuxline.vimrc")) - source ~/.config/nvim/tmuxline.vimrc -endif - -" Indent setup -if filereadable(expand("~/.config/nvim/lua/indent.lua")) - lua require('indent') -endif - " Git setup if filereadable(expand("~/.config/nvim/git.vimrc")) source ~/.config/nvim/git.vimrc endif +" Autocomplete +if has_key(g:plugs, "nvim-cmp") && filereadable(expand("~/.config/nvim/nvim-cmp.vimrc")) + source ~/.config/nvim/nvim-cmp.vimrc +endif + +" Autopairs +if has_key(g:plugs, "nvim-autopairs") && has_key(g:plugs, "treesitter.nvim") && filereadable(expand("~/.config/nvim/autopairs.vimrc")) + source ~/.config/nvim/autopairs.vimrc +endif + +" LSP +if has_key(g:plugs, "nvim-lspconfig") && has_key(g:plugs, "cmp-nvim-lsp") && filereadable(expand("~/.config/nvim/lspconfig.vimrc")) + source ~/.config/nvim/lspconfig.vimrc +endif + +" Gitsigns setup +if has_key(g:plugs, "gitsigns.nvim") && filereadable(expand("~/.config/nvim/gitsigns.vimrc")) + source ~/.config/nvim/gitsigns.vimrc +endif + +" Telescope setup +if has_key(g:plugs, "telescope.nvim") && filereadable(expand("~/.config/nvim/telescope.vimrc")) + source ~/.config/nvim/telescope.vimrc +endif + +" Search +if has_key(g:plugs, "nvim-hlslens") && filereadable(expand("~/.config/nvim/hlslens.vimrc")) + source ~/.config/nvim/hlslens.vimrc +endif + +" Lightline setup +if has_key(g:plugs, "lightline.vim") && filereadable(expand("~/.config/nvim/lightline.vimrc")) + source ~/.config/nvim/lightline.vimrc +endif + +" Tmuxline setup +if has_key(g:plugs, "tmuxline.vim") && filereadable(expand("~/.config/nvim/tmuxline.vimrc")) + source ~/.config/nvim/tmuxline.vimrc +endif + +" Indent setup +if has_key(g:plugs, "indent-blankline.nvim") && filereadable(expand("~/.config/nvim/lua/indent.lua")) + lua require('indent') +endif + " Scrollbar -if filereadable(expand("~/.config/nvim/scrollbar.vimrc")) +if has_key(g:plugs, "nvim-scrollbar") && filereadable(expand("~/.config/nvim/scrollbar.vimrc")) source ~/.config/nvim/scrollbar.vimrc endif " Tree setup -if filereadable(expand("~/.config/nvim/nvimtree.vimrc")) +if has_key(g:plugs, "nvim-tree.lua") && filereadable(expand("~/.config/nvim/nvimtree.vimrc")) source ~/.config/nvim/nvimtree.vimrc endif " Projections -if filereadable(expand("~/.config/nvim/projections.vimrc")) +if has_key(g:plugs, "vim-projectionist") && filereadable(expand("~/.config/nvim/projections.vimrc")) source ~/.config/nvim/projections.vimrc endif " Test setup -if filereadable(expand("~/.config/nvim/test.vimrc")) +if has_key(g:plugs, "vim-test") && filereadable(expand("~/.config/nvim/test.vimrc")) source ~/.config/nvim/test.vimrc endif " Markdown setup -if filereadable(expand("~/.config/nvim/markdown.vimrc")) +if has_key(g:plugs, "vim-markdown") && filereadable(expand("~/.config/nvim/markdown.vimrc")) source ~/.config/nvim/markdown.vimrc endif " Rust tools -if filereadable(expand("~/.config/nvim/rust-tools.vimrc")) +if has_key(g:plugs, "rust-tools.nvim") && has_key(g:plugs, "nvim-lspconfig") && filereadable(expand("~/.config/nvim/rust-tools.vimrc")) source ~/.config/nvim/rust-tools.vimrc endif " Color setup -if filereadable(expand("~/.config/nvim/colors.vimrc")) +if has_key(g:plugs, "sonokai") && filereadable(expand("~/.config/nvim/colors.vimrc")) source ~/.config/nvim/colors.vimrc endif