From fab5fedd727106510547a2ae3c086e9cba659e44 Mon Sep 17 00:00:00 2001 From: subcrip Date: Fri, 29 Mar 2024 08:46:25 +0800 Subject: [PATCH] Update init.lua --- init.lua | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/init.lua b/init.lua index 6e61836..17b9fae 100644 --- a/init.lua +++ b/init.lua @@ -417,7 +417,9 @@ local plugins = { } }, { 'Civitasv/cmake-tools.nvim' }, - { 'p00f/cphelper.nvim' } + { 'p00f/cphelper.nvim' }, + { "savq/melange-nvim" }, + { 'hrsh7th/vim-vsnip' } } local opts = { } @@ -469,7 +471,8 @@ require("monokai-pro").setup({ }, }) -vim.cmd([[colorscheme monokai-pro]]) +-- vim.cmd([[colorscheme monokai-pro]]) +vim.cmd([[colorscheme melange]]) local builtin = require("telescope.builtin") vim.keymap.set('n', 'p', builtin.find_files, {}) @@ -498,21 +501,47 @@ end vim.opt.completeopt = "menu,menuone,noselect" +local has_words_before = function() + unpack = unpack or table.unpack + 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 feedkey = function(key, mode) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true) +end + cmp.setup({ snippet = { expand = function(args) luasnip.lsp_expand(args.body) end, }, - mapping = cmp.mapping.preset.insert({ - [""] = cmp.mapping.select_prev_item(), -- previous suggestion - [""] = cmp.mapping.select_next_item(), -- next suggestion - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), -- show completion suggestions - [""] = cmp.mapping.abort(), -- close completion window - [""] = cmp.mapping.confirm({ select = true }), - }), + mapping = { + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.confirm({ select = true }) + elseif luasnip_status and luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), + + [""] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item() + elseif vim.fn["vsnip#jumpable"](-1) == 1 then + feedkey("(vsnip-jump-prev)", "") + end + end, { "i", "s" }), + + [''] = cmp.mapping.select_prev_item(), + [''] = cmp.mapping.select_next_item(), + [''] = cmp.mapping.abort(), + }, -- sources for autocompletion sources = cmp.config.sources({ { name = "nvim_lsp" }, -- LSP