nvim-cmp
nvim-cmp copied to clipboard
No option to confirm current selected completion and open next completion in command mode (wildcharm)
FAQ
- [X] I have checked the FAQ and it didn't resolve my problem.
Announcement
- [X] I have checked Breaking change announcement.
Minimal reproducible full config
" vim: ft=vim
set nocompatible
" --------------------------------
" Automatic install of plug-vim
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
if empty(glob('~/.config/nvim/autoload/plug.vim'))
silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
call plug#begin('~/.vim/bundle')
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
call plug#end()
lua <<LUA
lsp_capabilities = require('cmp_nvim_lsp').default_capabilities(lsp_capabilities)
local cmp = require'cmp'
local mapping = cmp.mapping.preset.insert({
['<Up>'] = cmp.mapping({
c = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
cmp.complete()
else
fallback()
end
end
}),
['<Down>'] = cmp.mapping({
c = function(fallback)
if cmp.visible() then
cmp.select_next_item()
cmp.mapping.complete()
else
fallback()
end
end
}),
['<Right>'] = cmp.mapping({
c = function(fallback)
if cmp.visible() then
cmp.confirm()
-- would like to confirm the current choice, close the current menu, and
-- open a new menu with the next completion choices
cmp.complete() -- this does not re-open a completion menu
else
fallback()
end
end
}),
})
cmp.setup({
window = {
documentation = cmp.config.window.bordered(),
},
mapping = mapping,
sources = cmp.config.sources({
{ name = 'buffer' },
{ name = 'path' },
{ name = 'nvim_lsp' },
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({'/', '?'}, {
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
-- <https://github.com/hrsh7th/nvim-cmp/discussions/1731>
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-- ]]
LUA
Description
There is no option to confirm the current selected completion and open the next completion after that in command mode.
Here is the behavior I'd like to replicate (except I'd like to switch left/right/down mappings:
- prepare working directory for completion items:
mkdir -p a/b/c a/bb/cc aa/b/c aa/bb/cc
- open nvim with no vimrc:
mvim -u /dev/null
- start command:
:e a<Tab>
- choose completion folder using
<Left>
or<Right>
, choose eithera
oraa
- validate using
<Down>
, the chosen directory is completed on the command line and a new completion menu opens up for the next folder level
Steps to reproduce
- prepare working directory for completion items:
mkdir -p a/b/c a/bb/cc aa/b/c aa/bb/cc
- open neovim with vimrc:
nvim -u vimrc
- start command:
:e a<Tab>
- choose completion folder using
<Up>
or<Down>
, choose eithera
oraa
- validate using
<Right>
, the chosen directory is completed on the command line
Expected behavior
I would like a new menu to open to be able to select the subfolders of a or aa
Actual behavior
The completion is validated, menu is closed, no new menu opens up
Additional context
This can be implemented without nvim-cmp using wildcharm that defines a mapping that will re-open the completion menu:
" cmdline mapping (conflicts with nvim-cmp and cmd-cmdline)
" <https://vi.stackexchange.com/questions/22627/switching-arrow-key-mappings-for-wildmenu-tab-completion>
set wildcharm=<C-Z>
cnoremap <expr> <up> wildmenumode() ? "\<left>" : "\<up>"
cnoremap <expr> <down> wildmenumode() ? "\<right>" : "\<down>"
cnoremap <expr> <left> wildmenumode() ? "\<up>" : "\<left>"
cnoremap <expr> <right> wildmenumode() ? " \<bs>\<C-Z>" : "\<right>"
Unfortunately, I cannot use this as it conflicts with nvim-cmp that replaces the keymap.