hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.44k stars 370 forks source link

Key map not working as expected after installed plugin. #1910

Open snoymy opened 1 month ago

snoymy commented 1 month ago

FAQ

Announcement

Minimal reproducible full 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

" Example key mapping to reproduce
nnoremap oo o<Esc>
inoremap mm pp

" Some other example case
nnoremap t o
nnoremap tt o<Esc>
inoremap mm pp

nnoremap r i
nnoremap rr i<Esc>
inoremap mm pp

Description

Key map in insert mode not work as expected after entered insert mode by key (First Character) in normal mode that have other key map that start with same key (First Character).

Steps to reproduce

  1. Add nvim-cmp plugin without or with setup
  2. Add key map for normal mode and add key map for insert mode as shown in Minimal reproducible full config.
    
    " eg 1:
    nnoremap oo o<Esc>
    inoremap mm pp

" eg 2: nnoremap t o nnoremap tt o inoremap mm pp

" eg 3: nnoremap r i nnoremap rr i inoremap mm pp


3. Enter normal mode in neovim then hit `omm` or `tmm` or `rmm`

### Expected behavior

Neovim enter insert mode and `mm` turn into `pp`

### Actual behavior

Text still `mm`

### Additional context

After remove `Plug 'hrsh7th/nvim-cmp'` key map work as expected.
snoymy commented 1 month ago

After I tinkering around I found that in this line of code, if I put 'in' into the second parameter feedkeys.call('', 'in', callback) it fix the problem. https://github.com/hrsh7th/nvim-cmp/blob/8f3c541407e691af6163e2447f3af1bd6e17f9a3/lua/cmp/utils/async.lua#L173