Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue May 24, 2023 · 4 comments

Comments

@benwoodward
Copy link

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).

CleanShot.2023-05-25.at.10.51.45.mp4
@wvculfckln6002
Copy link

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

@nanozuki
Copy link

nanozuki commented Sep 5, 2023

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

@nanozuki
Copy link

nanozuki commented Sep 5, 2023

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',
  },
  ...
})

@ghost
Copy link

ghost commented Apr 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants