Skip to content

Insert mode <C-r> mapping is not triggered after calling complete() #20004

@echasnovski

Description

@echasnovski

Steps to reproduce

  1. Create the following 'init.vim':

    set nocompatible
    
    let g:n = 0
    inoremap <C-r> <Cmd>let g:n += 1<CR>
    
    nnoremap <M-m> <Cmd>startinsert<CR><Cmd>call complete(col("."), [])<CR>
  2. vim --clean -u init.vim

  3. Press <M-m>. It starts Insert mode with empty+hidden completion menu.

  4. Press <C-r>. It indicates that it waits for a register id. Press a and <Esc> to finish it. Executing :echo g:n shows 0, which means that custom mapping was never used.

  5. Start Insert mode with i, press <C-r>, and go back to Normal mode. Executing :echo g:n shows 1, which means that custom mapping was used.

Notes:

  • The same behavior is observed if complete() is used with one or more string candidates.
  • Custom mapping works as expected if Insert mode completion is started with a built-in mapping. In Insert mode type ab abc a, press <C-n>. This shows a pmenu. Pressing <C-r> does not ask for register and executing :echo g:n later shows increase in g:n value.

Expected behaviour

Custom <C-r> mapping in Insert mode should be executed regardless of whether there is a completion menu shown with complete().

Version of Vim

9.2.316

Environment

OS: EndeavourOS Linux x86_64, 6.19.11-arch1-1
Terminal: Ghostty 1.3.1-arch2
$TERM: xterm-ghostty
Shell: Nu 0.111.0

Logs and stack traces

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions