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