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

select prev/next item mapping not working for cmdline case #809

Closed
2 tasks done
robbienohra opened this issue Feb 19, 2022 · 4 comments
Closed
2 tasks done

select prev/next item mapping not working for cmdline case #809

robbienohra opened this issue Feb 19, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@robbienohra
Copy link

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Issues

  • I have checked existing issues and there are no open or closed issues with the same problem.

Neovim Version

0.6.1

Minimal reproducible config

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<Left>'] = cmp.mapping.select_prev_item(),
    ['<Right>'] = cmp.mapping.select_next_item(),
  },

  sources = {
    { name = "nvim_lsp" },
    { name = "buffer" },
  },
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())

require'lspconfig'.clangd.setup {
  capabilities = capabilities,
}
EOF

Description

When I try to navigate to next/previous items in code (e.g. a cpp file) then the Left and Right custom mappings work (I can navigate to previous/next items using left/right keys).

However, if I enter command mode : then the left/right keys no longer work to navigate to prev/next items and I still need to use the tab key.

Steps to reproduce

Open a cpp file and type #include — note that left/right arrows navigate to prev/next items.

Enter command mode via : and type in something to prompt auto-complete suggestions. Note that left/right arrows no longer navigate to prev/next items. Note that the tab key works to navigate items.

Expected behavior

Left/right keys work to navigate between items in command mode.

Actual behavior

Left/right keys do not work to navigate between items in command mode.

Additional context

No response

@robbienohra robbienohra added the bug Something isn't working label Feb 19, 2022
@hrsh7th
Copy link
Owner

hrsh7th commented Feb 25, 2022

You should change the mapping as following.

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<Left>'] = cmp.mapping.select_prev_item(),
    ['<Right>'] = cmp.mapping.select_next_item(),
  },

↓↓↓

  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<Left>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }),
    ['<Right>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),
  },

@hrsh7th hrsh7th closed this as completed Feb 25, 2022
@robbienohra
Copy link
Author

Worked like a charm, thanks!

cexoso pushed a commit to cexoso/nvim that referenced this issue Apr 14, 2022
cexoso pushed a commit to cexoso/nvim that referenced this issue Apr 20, 2022
acristoffers added a commit to acristoffers/nvim-flake that referenced this issue Jul 9, 2024
As per hrsh7th/nvim-cmp#809. Not yet tested as
I can only reproduce the problem inside Docker.
acristoffers added a commit to acristoffers/nvim-flake that referenced this issue Sep 15, 2024
As per hrsh7th/nvim-cmp#809. Not yet tested as
I can only reproduce the problem inside Docker.
@ginolegigot
Copy link

ginolegigot commented Sep 16, 2024

hey!
i tried both
['<S-Up>'] = cmp.mapping.select_prev_item({behavior = 'select'}),
['<S-Down>'] = cmp.mapping.select_next_item({behavior = 'select'}),

and
['<Left>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c' }),
['<Right>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c' }),

But the up and down arrow keys seem to be still used to navigate through the autocompletion menu. Any hints ?

@ginolegigot
Copy link

ginolegigot commented Sep 16, 2024

Ok nevermind, this way of declaring the keymaps work:

  mapping = {
    ["<S-n>"] = cmp.mapping.select_next_item { behavior = cmp.SelectBehavior.Insert },
    ["<S-p>"] = cmp.mapping.select_prev_item { behavior = cmp.SelectBehavior.Insert },
  },

(thx tj)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants