From 0b837ee1f01423b7b7d435fb6483b986c206b301 Mon Sep 17 00:00:00 2001 From: Adam <56338480+adastx@users.noreply.github.com> Date: Fri, 22 Oct 2021 17:04:46 +0200 Subject: vim + nvim cleanup, UltiSnip -> LuaSnip --- .config/nvim/lua/opts.lua | 82 ++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 43 deletions(-) (limited to '.config/nvim/lua/opts.lua') diff --git a/.config/nvim/lua/opts.lua b/.config/nvim/lua/opts.lua index 56f066a..70b255c 100644 --- a/.config/nvim/lua/opts.lua +++ b/.config/nvim/lua/opts.lua @@ -1,27 +1,18 @@ -local nvim_lsp = require('lspconfig') -local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) - -local servers = { 'omnisharp', 'html', 'sumneko_lua', 'bashls', 'tsserver', 'cssls' } -for _, lsp in ipairs(servers) do - nvim_lsp[lsp].setup { - capabilities = capabilities, - } +-- CMP +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 +local luasnip = require("luasnip") +local cmp = require("cmp") +require("luasnip/loaders/from_vscode").lazy_load() vim.o.completeopt = 'menuone,noselect' --- CMP -local cmp = require 'cmp' - -local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) -end - cmp.setup { snippet = { expand = function(args) - vim.fn["UltiSnips#Anon"](args.body) + require('luasnip').lsp_expand(args.body) end, }, mapping = { @@ -29,29 +20,33 @@ cmp.setup { [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.close(), - -- [''] = cmp.mapping.confirm { - -- behavior = cmp.ConfirmBehavior.Replace, - -- select = true, - -- }, + [''] = cmp.mapping.close(), [""] = cmp.mapping(function(fallback) - if vim.fn["UltiSnips#CanJumpForwards"]() == 1 then - vim.fn.feedkeys(t(":call UltiSnips#JumpForwards()")) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() else fallback() end - end, { "i", "s", }), + end, { "i", "s" }), + [""] = cmp.mapping(function(fallback) - if vim.fn["UltiSnips#CanJumpBackwards"]() == 1 then - return vim.fn.feedkeys(t(":call UltiSnips#JumpBackwards()")) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) else fallback() end - end, { "i", "s", }), + end, { "i", "s" }), }, sources = { { name = 'nvim_lsp' }, - { name = 'ultisnips' }, + { name = 'luasnip' }, + -- { name = 'buffer' } }, } vim.cmd('autocmd FileType markdown lua require("cmp").setup.buffer { enabled = false }') @@ -68,6 +63,18 @@ require("nvim-autopairs.completion.cmp").setup { }, } +-- LSPCONFIG +local nvim_lsp = require('lspconfig') +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) + +local servers = { 'omnisharp', 'html', 'sumneko_lua', 'bashls', 'tsserver', 'cssls' } +for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { + capabilities = capabilities, + } +end + -- C# local pid = vim.fn.getpid() @@ -117,7 +124,7 @@ require'lspconfig'.bashls.setup{} -- Misc require'lsp_signature'.setup { - hint_enable = false, + floating_window = false } require'nvim-treesitter.configs'.setup { @@ -126,26 +133,15 @@ require'nvim-treesitter.configs'.setup { }, } -require("toggleterm").setup{ - size = 15, - open_mapping = [[]], - hide_numbers = true, - persist_size = true, - direction = 'horizontal', - close_on_exit = true, -} - -require('kommentary.config').use_extended_mappings() require('kommentary.config').configure_language("default", { prefer_single_line_comments = true, }) -vim.o.tabline = '%!v:lua.require\'luatab\'.tabline()' require("indent_blankline").setup { char = "¦", show_trailing_blankline_indent = false, - buftype_exclude = {"startify", "NvimTree", "help", "toggleterm", "terminal"}, - filetype_exclude = {"startify", "NvimTree", "help", "toggleterm", "terminal"}, + buftype_exclude = {"startify", "help", "terminal"}, + filetype_exclude = {"startify", "help", "terminal"}, } vim.cmd [[ -- cgit v1.2.3-70-g09d2