Something went wrong. Try again.
Vim/Neovim configurations just for me
neovim
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140local cmp = require("cmp")
local skkeleton = require("rc.skkeleton")local ui = require("rc.ui")
local opts = {}
opts.enabled = function() if skkeleton.is_enabled() then return false end return trueend
opts.sources = { { name = "nvim_lsp" }, { name = "path" }, { name = "buffer" },}
opts.completion = { completeopt = vim.o.completeopt,}
local function has_words_before() local cursor = vim.api.nvim_win_get_cursor(0) local line, col = cursor[1], cursor[2] return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nilend
local mapping = cmp.mapping
opts.mapping = mapping.preset.insert({ ["<Tab>"] = mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif vim.snippet.active({ direction = 1 }) then vim.snippet.jump(1) elseif vim.lsp.inline_completion.get() then return elseif has_words_before() then cmp.complete() else fallback() end end, { "i", "c", "s" }), ["<S-Tab>"] = mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif vim.snippet.active({ direction = -1 }) then vim.snippet.jump(-1) else fallback() end end, { "i", "c", "s" }), ["<CR>"] = mapping.confirm({ select = true }), ["<C-e>"] = mapping.abort(), ["<C-d>"] = mapping.scroll_docs(-4), ["<C-f>"] = mapping.scroll_docs(4),})
opts.snippet = { expand = function(args) vim.snippet.expand(args.body) end,}
opts.window = { completion = { winhighlight = "Normal:Pmenu,CursorLine:PmenuSel,FloatBorder:FloatBorder,Search:None", col_offset = -3, side_padding = 0, scrollbar = true, scrolloff = 8, winblend = 11, }, documentation = { winhighlight = "Normal:Pmenu,FloatBorder:FloatBorder,Search:None", winblend = 11, },}
opts.formatting = { fields = { "kind", "abbr", "menu" }, ---@type fun(entry, vim_item): any format = function(_, vim_item) vim_item.kind = " " .. ui.kind[vim_item.kind] .. "⠀" vim_item.abbr = ui.truncate(vim_item.abbr:gsub(vim.pesc("..."), ui.ellipsis), 50) do local menu = vim_item.menu or "" if vim.bo.filetype == "rust" then menu = menu:gsub("%(use ([^%)]+)%)%s*(.*)", "%2 (%1)") :gsub("%(alias ([^%)]+)%)%s*(.*)", "%2 (alias %1)") :gsub("%(as [^%)]+%)", "") :gsub("unsafe ", "") :gsub("const ", "") end vim_item.menu = ui.truncate(vim.fn.trim(menu), 70) end return vim_item end,}
cmp.setup(opts)
cmp.setup.cmdline(":", { mapping = cmp.mapping.preset.cmdline(), sources = cmp.config.sources({ { name = "path" }, }, { { name = "cmdline" }, }),})
cmp.setup.cmdline({ "/", "?" }, { mapping = cmp.mapping.preset.cmdline(), sources = { { name = "buffer" }, },})
-- if border ~= 'none' then-- local thumb = {}-- for _ = 1, vim.o.lines do-- table.insert(thumb, '┃')-- end-- require('cmp.utils.buffer').cache = setmetatable({}, {-- ---@param name string|integer-- ---@param buf buffer-- __newindex = function(t, name, buf)-- if type(name) == 'string' and name:find('thumb_buf') then-- vim.api.nvim_buf_set_lines(buf, 0, 1, false, thumb)-- end-- rawset(t, name, buf)-- end,-- })-- end