Keymap normalization not compatible with <Leader> key
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
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 }),
['<Leader>g<Space>'] = cmp.mapping.complete()
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "buffer" },
}),
}
EOF
lua << EOF
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require'lspconfig'.cssls.setup {
capabilities = capabilities,
}
EOF
Description
Add this config:
mapping = {
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<Leader>g<Space>'] = cmp.mapping.complete()
},
This keymap <Leader>g<Space> is not functioning properly, while it was working fine before.
Result with imap:
i <*Leader>g<Space> * <Lua 24: /tmp/plugged/vim-plug/nvim-cmp/lua/cmp/utils/keymap.lua:133>
cmp.utils.keymap.set_map
Steps to reproduce
Included in reproducible config file.
Expected behavior
The keymap should worked.
Actual behavior
It not worked after upgrade cmp. Result in imap looks wired.
Additional context
No response
Not sure if is this a bug of vim/nvim:
let g:mapleader = "\<Space>"
map <Leader> <Cmd>echo "work"<CR>
map <*Leader> <Cmd>echo "not work"<CR>
map <Space> <Cmd>echo "work"<CR>
map <*Space> <Cmd>echo "work"<CR>
But here is a workaround:
'<Leader>g<Space>' -> (vim.g.mapleader or '\\') .. 'g<Space>'
https://github.com/hrsh7th/nvim-cmp/pull/2073
Please test the latest version.
#2073
Please test the latest version.
I tried the latest version, but the problem still persists.
I guess this commit caused the issue: https://github.com/hrsh7th/nvim-cmp/commit/19bd8c7c9a834e31db1f15cb04635bf44219a7cb. It attempted to use <*xxx> to properly handle the modifier key, but <Leader> is not a terminal keycode.
The workaround solution is working well, thanks for your help!