From 7df52095b08341146f7eee633363faa74a639b13 Mon Sep 17 00:00:00 2001 From: Adam <56338480+adastx@users.noreply.github.com> Date: Fri, 8 Oct 2021 22:14:57 +0200 Subject: Vim disabled swapfiles, working snippets --- .config/nvim/lua/opts.lua | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to '.config/nvim/lua/opts.lua') diff --git a/.config/nvim/lua/opts.lua b/.config/nvim/lua/opts.lua index 126d6c4..ecae0af 100644 --- a/.config/nvim/lua/opts.lua +++ b/.config/nvim/lua/opts.lua @@ -1,4 +1,3 @@ --- SNIPPETS local nvim_lsp = require('lspconfig') local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) @@ -11,14 +10,23 @@ for _, lsp in ipairs(servers) do end vim.o.completeopt = 'menuone,noselect' -local luasnip = require 'luasnip' -- CMP local cmp = require 'cmp' + +local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local check_back_space = function() + local col = vim.fn.col(".") - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil +end + cmp.setup { snippet = { expand = function(args) - require('luasnip').lsp_expand(args.body) + vim.fn["UltiSnips#Anon"](args.body) end, }, mapping = { @@ -26,34 +34,35 @@ cmp.setup { [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.complete(), [''] = cmp.mapping.close(), [''] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, - [''] = function(fallback) - if vim.fn.pumvisible() == 1 then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n') - elseif luasnip.expand_or_jumpable() then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-expand-or-jump', true, true, true), '') + [""] = cmp.mapping(function(fallback) + if vim.fn.complete_info()["selected"] == -1 and vim.fn["UltiSnips#CanExpandSnippet"]() == 1 then + vim.fn.feedkeys(t("=UltiSnips#ExpandSnippet()")) + elseif vim.fn["UltiSnips#CanJumpForwards"]() == 1 then + vim.fn.feedkeys(t(":call UltiSnips#JumpForwards()")) + elseif vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(t(""), "n") else fallback() end - end, - [''] = function(fallback) - if vim.fn.pumvisible() == 1 then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('', true, true, true), 'n') - elseif luasnip.jumpable(-1) then - vim.fn.feedkeys(vim.api.nvim_replace_termcodes('luasnip-jump-prev', true, true, true), '') + end, { "i", "s", }), + [""] = cmp.mapping(function(fallback) + if vim.fn["UltiSnips#CanJumpBackwards"]() == 1 then + return vim.fn.feedkeys(t(":call UltiSnips#JumpBackwards()")) + elseif vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(t(""), "n") else fallback() end - end, + end, { "i", "s", }), }, sources = { + { name = 'ultisnips' }, { name = 'nvim_lsp' }, - { name = 'luasnip' }, }, } -- cgit v1.2.3-70-g09d2