hrsh7th / cmp-cmdline

nvim-cmp source for vim's cmdline
MIT License
493 stars 42 forks source link

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

Open benwoodward opened 1 year ago

benwoodward commented 1 year ago

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

wvculfckln6002 commented 1 year ago

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

nanozuki commented 10 months ago

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

nanozuki commented 10 months ago

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',
  },
  ...
})
kzlouge commented 2 months ago

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.