Skip to content

Any way to randomize order of sources #1979

Closed Answered by mrloop
mrloop asked this question in Q&A
Discussion options

You must be logged in to vote

Think I've got it working be adapting a suggestion in the wiki https://github.com/hrsh7th/nvim-cmp/wiki/Advanced-techniques#disable--enable-cmp-sources-only-on-certain-buffers


local function shuffle(t)
  local n = #t
  for i = n, 2, -1 do
    local j = math.random(1, i)
    t[i], t[j] = t[j], t[i]
  end
  return t;
end

vim.api.nvim_create_autocmd('BufReadPre', {
  callback = function(t)
    local sources = cmp.config.sources({
      { name = 'nvim_lsp' },
      { name = 'luasnip' },
      { name = 'path' },
    }, shuffle({
      { name = 'nvim-cmp-ts-tag-close' },
      { name = "codeium" },
      { name = 'copilot'},
      { name = 'supermaven'},
      { name = 'nvim_lua' },
      { n…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by mrloop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant