diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua index 5506f4d..c684168 100644 --- a/.config/nvim/lua/plugins.lua +++ b/.config/nvim/lua/plugins.lua @@ -5,7 +5,7 @@ return require('packer').startup(function() use 'wbthomason/packer.nvim' use 'ray-x/lsp_signature.nvim' use 'jose-elias-alvarez/nvim-lsp-ts-utils' - use 'L3MON4D3/LuaSnip' + use 'rafamadriz/friendly-snippets' use { 'b3nj5m1n/kommentary', @@ -20,6 +20,13 @@ return require('packer').startup(function() end } + use { + 'L3MON4D3/LuaSnip', + config = function() + require("luasnip/loaders/from_vscode").lazy_load() + end + } + use { 'hrsh7th/nvim-cmp', requires = { @@ -28,11 +35,17 @@ return require('packer').startup(function() 'hrsh7th/cmp-buffer', 'hrsh7th/cmp-path', 'hrsh7th/cmp-cmdline', + 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip', }, config = function() - local cmp = require'cmp' - -- local cmp = require('hrsh7th/nvim-cmp') + local cmp = require'cmp' + local luasnip = require'luasnip' + + local has_words_before = function() + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil + end cmp.setup({ @@ -50,25 +63,34 @@ return require('packer').startup(function() }), }, + documentation = { + border = 'rounded' + }, + + snippet = { expand = function(args) - require('luasnip').lsp_expand(args.body) + luasnip.lsp_expand(args.body) end, }, mapping = { + [''] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }), [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm({ - select = false, + [''] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), }), + [''] = cmp.mapping(cmp.mapping.confirm({ select = false }), { 'i', 'c' }), + [''] = cmp.mapping(cmp.mapping.confirm({ select = false }), { 'i', 'c' }), [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), [""] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() - elseif luasnip.expand_or_jumpable() then + elseif luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() elseif has_words_before() then cmp.complete() @@ -93,7 +115,10 @@ return require('packer').startup(function() priority = 1, }, - { name = 'luasnip' }, + { + name = 'luasnip', + priority = 4, + }, { name = 'tmux', priority = 2,