hrsh7th/nvim-cmp

Setting mapping in `cmp.setup.cmdline({'/', '?'}, {` prevents command tab completion from working after search

Open

#1,511 opened on Apr 1, 2023

View on GitHub
 (10 comments) (3 reactions) (0 assignees)Lua (437 forks)batch import
bugdifficulthelp wanted

Repository metrics

Stars
 (9,420 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

FAQ

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

Announcement

Minimal reproducible full config

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/cmp-cmdline'
Plug 'neovim/nvim-lspconfig'

Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-calc'

call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true })
  },
  sources = cmp.config.sources({
    { name = "nvim_lsp" },
    { name = "buffer" },
  }),
}
local capabilities = require('cmp_nvim_lsp').default_capabilities()

cmp.setup.cmdline({'/', '?'}, {
    -- setting mapping causes the issue of :e %^I after / search
    mapping = cmp.mapping.preset.cmdline(),
    sources = {
        { name = 'buffer' }
    }
})
EOF

Description

When mapping = cmp.mapping.preset.cmdline(), is provided to the /, ? cmp cmdlines, after searching once tab completion in the vim commandline stops working and prints ^I instead. If you remove the mapping then the problem won't trigger.

Steps to reproduce

  1. Open some file with nvim using attached minimal config
  2. Verify that :e %<tab> will actually tab-expand % to current filename.
  3. Perform search using /foo<CR> or equivalent; verify that :e %<tab> will not work anymore and instead, print ^I per tab invocation.
  4. Comment out mapping line in example config and verify (3) above cannot be reproduced.

Expected behavior

:e %<tab> will expand current filename after performing at least one search

Actual behavior

:e %<tab> will expand to :e %^I which is not expected.

Additional context

I don't know the significance of the mapping attribute for the search cmdline config but I merely copy-pasted it from the reference manual/README.

Contributor guide