From 102c60f34361a2facb6310eae2e8dc0da8a1f0cd Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sun, 17 Jul 2022 11:01:15 -0500 Subject: nvim: rejigger some configs --- nvim/.config/nvim/lua/cmp_config.lua | 20 ++++++++++++++------ nvim/.config/nvim/lua/plugins.lua | 26 ++++++++++++++++++-------- nvim/.config/nvim/lua/vsnip_config.lua | 27 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 nvim/.config/nvim/lua/vsnip_config.lua diff --git a/nvim/.config/nvim/lua/cmp_config.lua b/nvim/.config/nvim/lua/cmp_config.lua index fa1610f..fcad211 100644 --- a/nvim/.config/nvim/lua/cmp_config.lua +++ b/nvim/.config/nvim/lua/cmp_config.lua @@ -15,20 +15,28 @@ cmp.setup({ -- documentation = cmp.config.window.bordered(), }, mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Insert, + select = true, + }), }), sources = cmp.config.sources({ + { name = 'nvim_lua' }, { name = 'nvim_lsp' }, { name = 'vsnip' }, -- For vsnip users. -- { name = 'luasnip' }, -- For luasnip users. -- { name = 'ultisnips' }, -- For ultisnips users. -- { name = 'snippy' }, -- For snippy users. { name = 'path' }, - }) + }), + + experimental = { + ghost_text = true, + }, }) -- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). diff --git a/nvim/.config/nvim/lua/plugins.lua b/nvim/.config/nvim/lua/plugins.lua index c578dbc..6fa67f0 100644 --- a/nvim/.config/nvim/lua/plugins.lua +++ b/nvim/.config/nvim/lua/plugins.lua @@ -34,16 +34,14 @@ return require('packer').startup(function() config = function() require('neogit_config') end } + -- Snippets use { - 'neovim/nvim-lspconfig', - requires = { - "jose-elias-alvarez/null-ls.nvim", - "jose-elias-alvarez/nvim-lsp-ts-utils", - "hrsh7th/cmp-nvim-lsp'", - }, - config = function() require('lsp_config') end + 'hrsh7th/vim-vsnip', + config = function() require('vsnip_config') end, } + use 'hrsh7th/vim-vsnip-integ' + -- Completion use { 'hrsh7th/nvim-cmp', requires = { @@ -51,9 +49,21 @@ return require('packer').startup(function() 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', + 'hrsh7th/cmp-nvim-lua', 'hrsh7th/vim-vsnip', }, - config = function() require('cmp_config') end + config = function() require('cmp_config') end, + } + + -- Language server support + use { + 'neovim/nvim-lspconfig', + requires = { + 'jose-elias-alvarez/null-ls.nvim', + 'jose-elias-alvarez/nvim-lsp-ts-utils', + 'hrsh7th/cmp-nvim-lsp', + }, + config = function() require('lsp_config') end, } use { diff --git a/nvim/.config/nvim/lua/vsnip_config.lua b/nvim/.config/nvim/lua/vsnip_config.lua new file mode 100644 index 0000000..f7c2836 --- /dev/null +++ b/nvim/.config/nvim/lua/vsnip_config.lua @@ -0,0 +1,27 @@ +-- NOTE: You can use other key to expand snippet. + +-- Expand +vim.cmd("imap vsnip#expandable() ? '(vsnip-expand)' : ''") +vim.cmd("smap vsnip#expandable() ? '(vsnip-expand)' : ''") + +-- Expand or jump +vim.cmd("imap vsnip#available(1) ? '(vsnip-expand-or-jump)' : ''") +vim.cmd("smap vsnip#available(1) ? '(vsnip-expand-or-jump)' : ''") + +-- Jump forward or backward +vim.cmd("imap vsnip#jumpable(1) ? '(vsnip-jump-next)' : ''") +vim.cmd("smap vsnip#jumpable(1) ? '(vsnip-jump-next)' : ''") +vim.cmd("imap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : ''") +vim.cmd("smap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : ''") + +-- Select or cut text to use as $TM_SELECTED_TEXT in the next snippet. +-- See https://github.com/hrsh7th/vim-vsnip/pull/50 +vim.cmd("nmap s (vsnip-select-text)") +vim.cmd("xmap s (vsnip-select-text)") +vim.cmd("nmap S (vsnip-cut-text)") +vim.cmd("xmap S (vsnip-cut-text)") + +-- If you want to use snippet for multiple filetypes, you can `g:vsnip_filetypes` for it. +vim.cmd("let g:vsnip_filetypes = {}") +vim.cmd("let g:vsnip_filetypes.javascriptreact = ['javascript']") +vim.cmd("let g:vsnip_filetypes.typescriptreact = ['typescript']") -- cgit v1.2.3