cmp-cmdline icon indicating copy to clipboard operation
cmp-cmdline copied to clipboard

first result auto-selected, but it doesn't search for the text in that result until I move selection down and back up again

Open benwoodward opened this issue 1 year ago • 4 comments

Here's an example, I search for 'comp', first result is 'compare' and is selected, I hit enter and it searches for 'comp'. To select and search 'compare' I need to hit tab+shift-tab + enter. Would be great if the first option wasn't selected until I tab to it (so I don't need to tab forwards and backwards to actually select it).

https://github.com/hrsh7th/cmp-cmdline/assets/1472981/4cd9c732-512d-434c-9328-46967625c959

benwoodward avatar May 24 '23 22:05 benwoodward

I am also troubled by this, let’s find a solution together.

wvculfckln6002 avatar May 25 '23 04:05 wvculfckln6002

I am also troubled by this to long. Also troubled in :

nanozuki avatar Sep 05 '23 01:09 nanozuki

Oh, I fix it.., by add an option to completion = { completeopt = 'menu,menuone,noselect' } to cmd.setup.cmdline().

-- `/` cmdline setup.
cmp.setup.cmdline({ '/', '?' }, {
  completion = { completeopt = 'menu,menuone,noselect' },
  sources = {
    { name = 'buffer' },
  },
})
-- `:` cmdline setup.
cmp.setup.cmdline(':', {
  completion = { completeopt = 'menu,menuone,noselect' },
  sources = cmp.config.sources(
    { { name = 'path' } },
    { { name = 'cmdline', option = { ignore_cmds = { 'Man', '!' } } } }
  ),
})

But I can't understand, I have added this option to cmd.setup. Why not used in cmd.cmdline:

cmp.setup({
  completion = {
    completeopt = 'menu,menuone,noinsert',
  },
  ...
})

nanozuki avatar Sep 05 '23 02:09 nanozuki

Using <C-y> to confirm the selection.

The default keybindings:

mapping.preset.cmdline = function(override)
  return merge_keymaps(override or {}, {
   -- omitted code
    ['<C-e>'] = {
      c = mapping.abort(),
    },
    ['<C-y>'] = {
      c = mapping.confirm({ select = false }),
    },
  })
end

You can override the default key by adding an argument to cmp.mapping.preset.cmdline:

      cmp.setup.cmdline(":", {
        mapping = cmp.mapping.preset.cmdline({
          ["<cr>"] = {
            c = cmp.mapping.confirm({ select = false }),
          },
        }),
        sources = cmp.config.sources({
          { name = "path" },
        }, {
          {
            name = "cmdline",
            option = {
              ignore_cmds = { "Man", "!" },
            },
          },
        }),
      })

In this case, then you can use <cr> to confirm.

kzlouge avatar Apr 16 '24 12:04 kzlouge