hrsh7th / cmp-cmdline

nvim-cmp source for vim's cmdline
MIT License
505 stars 41 forks source link

How to navigate results on command prompt? #57

Closed eduardoarandah closed 1 year ago

eduardoarandah commented 1 year ago

Let's say I want to run PackerCompile

I type pco and get this results:

image

How to navigate up and down?

tried key up /down and C-n C-p but it doesn't work

eduardoarandah commented 1 year ago

Found it on cmp readme.

shime commented 1 year ago

Here's the answer, for posterity.

You need to add mappings for cmdline mode as well. https://github.com/hrsh7th/nvim-cmp/issues/231#issuecomment-1098175017

cmp.setup.cmdline('/', {
  sources = {
    { name = 'buffer' }
  },
  mapping = cmp.mapping.preset.cmdline({
    ['<C-n>'] = cmp.mapping(cmp.mapping.select_next_item()),
    ['<C-p>'] = cmp.mapping(cmp.mapping.select_prev_item()),
    ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item()),
    ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
    ['<C-e>'] = cmp.mapping({
      i = cmp.mapping.abort(),
      c = cmp.mapping.close(),
    }),
  })
})
benbrastmckie commented 1 year ago

Here's the answer, for posterity.

Thanks for this. I'm looking for a solution along just these lines. However, I was unable to adapt the above to the commands and which I try to use to navigate all autocomplete menus. Here is what I have in my configuration for cmp:

-- cmp-cmdline
  -- `/` cmdline setup.
  cmp.setup.cmdline('/', {
    mapping = cmp.mapping.preset.cmdline({
      ['<C-j>'] = cmp.mapping(cmp.mapping.select_next_item()),
      ['<C-k>'] = cmp.mapping(cmp.mapping.select_prev_item()),
      ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
    }),
    sources = {
      { name = 'buffer' }
    }
  })
  -- `:` cmdline setup.
  cmp.setup.cmdline(':', {
    mapping = cmp.mapping.preset.cmdline({
      ['<C-j>'] = cmp.mapping(cmp.mapping.select_next_item()),
      ['<C-k>'] = cmp.mapping(cmp.mapping.select_prev_item()),
      ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
    }),
    sources = cmp.config.sources({
      { name = 'path' }
    }, {
      { name = 'cmdline',
        option = {
          ignore_cmds = { 'Man', '!' }
        }
      },
      mapping = cmp.mapping.preset.cmdline({}), -- fixes supertab
    }),
  })

Any help would be greatly appreciated!

windowsrefund commented 1 year ago

How is this marked as closed?