Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return {
- {
- "hrsh7th/cmp-vsnip",
- dependencies = {
- "hrsh7th/vim-vsnip",
- "rafamadriz/friendly-snippets",
- },
- },
- {
- "hrsh7th/nvim-cmp",
- dependencies = {
- "onsails/lspkind.nvim",
- "hrsh7th/cmp-path",
- "hrsh7th/cmp-buffer",
- "hrsh7th/cmp-nvim-lua",
- "hrsh7th/cmp-cmdline",
- "hrsh7th/cmp-nvim-lsp",
- },
- config = function()
- 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 cmp = require("cmp")
- cmp.setup.cmdline(":", {
- mapping = cmp.mapping.preset.cmdline(),
- sources = cmp.config.sources({
- { name = "path" },
- }, {
- {
- name = "cmdline",
- option = {
- ignore_cmds = { "Man", "!" },
- },
- },
- }),
- })
- cmp.setup({
- snippet = {
- expand = function(args)
- vim.snippet.expand(args.body)
- end,
- },
- formatting = {
- format = function(entry, vim_item)
- if vim.tbl_contains({ "path" }, entry.source.name) then
- local icon, hl_group =
- require("nvim-web-devicons").get_icon(entry:get_completion_item().label)
- if icon then
- vim_item.kind = icon
- vim_item.kind_hl_group = hl_group
- return vim_item
- end
- end
- return require("lspkind").cmp_format({ with_text = false })(entry, vim_item)
- end,
- },
- window = {
- completion = cmp.config.window.bordered(),
- documentation = cmp.config.window.bordered(),
- },
- mapping = cmp.mapping.preset.insert({
- ["<CR>"] = cmp.mapping({
- i = function(fallback)
- if cmp.visible() and cmp.get_active_entry() then
- cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
- else
- fallback()
- end
- end,
- s = cmp.mapping.confirm({ select = true }),
- c = function(fallback)
- if cmp.visible() and cmp.get_active_entry() then
- cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
- else
- fallback()
- end
- end,
- }),
- ["<Tab>"] = {
- i = function(fallback)
- if not cmp.select_next_item() then
- if vim.bo.buftype ~= "prompt" and has_words_before() then
- cmp.complete()
- else
- fallback()
- end
- end
- end,
- c = function(_)
- if cmp.visible() then
- if #cmp.get_entries() == 1 then
- cmp.confirm({ select = true })
- else
- cmp.select_next_item()
- end
- else
- cmp.complete()
- if #cmp.get_entries() == 1 then
- cmp.confirm({ select = true })
- end
- end
- end,
- },
- ["<S-Tab>"] = function(fallback)
- if not cmp.select_prev_item() then
- if vim.bo.buftype ~= "prompt" and has_words_before() then
- cmp.complete()
- else
- fallback()
- end
- end
- end,
- }),
- sources = cmp.config.sources({
- { name = "nvim_lsp" },
- { name = "vsnip" },
- { name = "nvim_lua" },
- {
- name = "path",
- option = {
- trailing_slash = false,
- label_trailing_slash = false,
- },
- },
- }, { { name = "buffer" } }),
- })
- end,
- },
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement