Update init.lua

This commit is contained in:
subcrip 2024-03-29 08:46:25 +08:00
parent 2f297983d5
commit fab5fedd72
1 changed files with 40 additions and 11 deletions

View File

@ -417,7 +417,9 @@ local plugins = {
} }
}, },
{ 'Civitasv/cmake-tools.nvim' }, { 'Civitasv/cmake-tools.nvim' },
{ 'p00f/cphelper.nvim' } { 'p00f/cphelper.nvim' },
{ "savq/melange-nvim" },
{ 'hrsh7th/vim-vsnip' }
} }
local opts = { 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") local builtin = require("telescope.builtin")
vim.keymap.set('n', '<leader>p', builtin.find_files, {}) vim.keymap.set('n', '<leader>p', builtin.find_files, {})
@ -498,21 +501,47 @@ end
vim.opt.completeopt = "menu,menuone,noselect" 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({ cmp.setup({
snippet = { snippet = {
expand = function(args) expand = function(args)
luasnip.lsp_expand(args.body) luasnip.lsp_expand(args.body)
end, end,
}, },
mapping = cmp.mapping.preset.insert({ mapping = {
["<C-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion ["<Tab>"] = cmp.mapping(function(fallback)
["<C-j>"] = cmp.mapping.select_next_item(), -- next suggestion if cmp.visible() then
["<C-b>"] = cmp.mapping.scroll_docs(-4), cmp.confirm({ select = true })
["<C-f>"] = cmp.mapping.scroll_docs(4), elseif luasnip_status and luasnip.expand_or_jumpable() then
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions luasnip.expand_or_jump()
["<ESC>"] = cmp.mapping.abort(), -- close completion window elseif has_words_before() then
["<tab>"] = cmp.mapping.confirm({ select = true }), cmp.complete()
}), else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { "i", "s" }),
['<C-k>'] = cmp.mapping.select_prev_item(),
['<C-j>'] = cmp.mapping.select_next_item(),
['<ESC>'] = cmp.mapping.abort(),
},
-- sources for autocompletion -- sources for autocompletion
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = "nvim_lsp" }, -- LSP { name = "nvim_lsp" }, -- LSP