Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return {
- 'hrsh7th/nvim-cmp',
- dependencies = { 'hrsh7th/cmp-nvim-lsp',
- 'L3MON4D3/LuaSnip',
- 'saadparwaiz1/cmp_luasnip',
- "hrsh7th/cmp-path",
- "hrsh7th/cmp-cmdline",
- "rafamadriz/friendly-snippets"
- },
- config = function()
- local status_cmp_ok, cmp = pcall(require, "cmp")
- local status_luasnip_ok, luasnip = pcall(require, "luasnip")
- -- local cmp_autopairs = require('nvim-autopairs.completion.cmp')
- -- local status_autopairs_ok, autopairs = pcall(require, " nvim-autopairs.completion.cmp")
- if not (status_cmp_ok or status_luasnip_ok) then
- print("CMP not loaded")
- vim.notify("CMP not working", "warn")
- return
- end
- luasnip.config.setup {}
- require('luasnip.loaders.from_vscode').lazy_load()
- local check_backspace = function()
- local col = vim.fn.col(".") - 1
- return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
- end
- local kind_icons = {
- Text = "",
- Method = "",
- Function = "",
- Constructor = "",
- Field = "",
- Variable = "",
- Class = "",
- Interface = "",
- Module = "",
- Property = "",
- Unit = "",
- Value = "",
- Enum = "",
- Keyword = "",
- Snippet = "",
- Color = "",
- File = "",
- Reference = "",
- Folder = "",
- EnumMember = "",
- Constant = "",
- Struct = "",
- Event = "",
- Operator = "",
- TypeParameter = "",
- }
- cmp.setup({
- snippet = {
- expand = function(args)
- luasnip.lsp_expand(args.body) -- For `luasnip` users.
- end,
- },
- mapping = cmp.mapping.preset.insert({
- -- ['<C-d>'] = cmp.mapping.scroll_docs( -4),
- -- ['<C-f>'] = cmp.mapping.scroll_docs(4),
- -- ['<CR>'] = cmp.mapping.confirm {
- -- behavior = cmp.ConfirmBehavior.Replace,
- -- select = true,
- -- },
- ["<C-k>"] = cmp.mapping.select_prev_item(),
- ["<C-j>"] = cmp.mapping.select_next_item(),
- ["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
- ["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
- ["<C-Space>"] = cmp.mapping(cmp.mapping.complete({}), { "i", "c" }),
- ["<C-e>"] = cmp.mapping({
- i = cmp.mapping.abort(),
- c = cmp.mapping.close(),
- }),
- -- Accept currently selected item. If none selected, `select` first item.
- -- Set `select` to `false` to only confirm explicitly selected items.
- ["<CR>"] = cmp.mapping.confirm({ select = true }),
- ["<Tab>"] = cmp.mapping(function(fallback)
- if cmp.visible() then
- cmp.select_next_item()
- elseif luasnip.expandable() then
- luasnip.expand()
- elseif luasnip.expand_or_jumpable() then
- luasnip.expand_or_jump()
- elseif check_backspace() then
- fallback()
- else
- fallback()
- end
- end, {
- "i",
- "s",
- }),
- ["<S-Tab>"] = cmp.mapping(function(fallback)
- if cmp.visible() then
- cmp.select_prev_item()
- elseif luasnip.jumpable(-1) then
- luasnip.jump(-1)
- else
- fallback()
- end
- end, {
- "i",
- "s",
- }),
- }),
- formatting = {
- fields = { "kind", "abbr", "menu" },
- format = function(entry, vim_item)
- vim_item.kind = kind_icons[vim_item.kind]
- vim_item.menu = ({
- nvim_lsp = "LSP",
- nvim_lua = "LUA",
- luasnip = "SNIP",
- buffer = "BUFF",
- path = "DIR",
- emoji = "EMOJI",
- })[entry.source.name]
- return vim_item
- end,
- },
- sources = {
- { name = "nvim_lsp" },
- { name = "nvim_lua" },
- { name = "luasnip" },
- { name = "buffer" },
- { name = "path" },
- },
- confirm_opts = {
- behavior = cmp.ConfirmBehavior.Replace,
- select = false,
- },
- window = {
- completion = cmp.config.window.bordered(),
- documentation = cmp.config.window.bordered(),
- },
- experimental = {
- ghost_text = true,
- },
- })
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment