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

Change select_next_item mapping #70

Open
benbrastmckie opened this issue Nov 19, 2022 · 2 comments
Open

Change select_next_item mapping #70

benbrastmckie opened this issue Nov 19, 2022 · 2 comments

Comments

@benbrastmckie
Copy link

I am attempting to get <C-j> and <C-k> to be the means by which I navigate menu options throughout nvim. Currently Tab and <S-Tab> work when selecting from options in the command line or search. I have tried the following but without success:

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

I tried checking the mapping with :verbose cmap <C-j> and similarly for <C-k> and found that no mapping was found before or after including the config given above. Any help would be much appreciated!

@AbelClapton
Copy link

I'm having the same problem. I've tried several mapping configs but couldn't make it work

@tmerse
Copy link

tmerse commented Feb 5, 2024

Had the same issue.
Looking at thecmp.mapping.preset.cmdline implementation (https://github.com/exosyphon/nvim/blob/2800baf59612b3a2498f9e764229fe05f6b1276a/after/plugin/lsp.lua#L63)

cmp.setup.cmdline('/', {
  mapping = cmp.mapping.preset.cmdline({
    ['<C-k>'] = {
      c = function()
        local cmp = require('cmp')
        if cmp.visible() then
          cmp.select_prev_item()
        else
          cmp.complete()
        end
      end,
    },
    ['<C-j>'] = {
      c = function()
        local cmp = require('cmp')
        if cmp.visible() then
          cmp.select_next_item()
        else
          cmp.complete()
        end
      end,
    },
  }),
  sources = {
    { name = 'buffer' }
  }
})

Did the trick for me (note cmp.select_next_item() vs cmp.mapping.select_next.item()

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