Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make <c-.> work again #2100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions lua/cmp/utils/keymap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local keymap = {}
---@param keys string
---@return string
keymap.t = function(keys)
return (string.gsub(keys, "(<[A-Za-z0-9\\%-%[%]%^@;,:_']->)", function(match)
return (string.gsub(keys, "(<[A-Za-z0-9\\%-%[%]%^@;,:_'.]->)", function(match)
return vim.api.nvim_eval(string.format([["\%s"]], match))
end))
end
Expand All @@ -17,24 +17,24 @@ end
---@param keys string
---@return string
keymap.normalize = vim.fn.has('nvim-0.8') == 1 and function(keys)
local t = string.gsub(keys, "<([A-Za-z0-9\\%-%[%]%^@;,:_']-)>", function(match)
-- Use the \<* notation, which distinguishes <C-J> from <NL>, etc.
return vim.api.nvim_eval(string.format([["\<*%s>"]], match))
end)
return vim.fn.keytrans(t)
end or function(keys)
local normalize_buf = buffer.ensure('cmp.util.keymap.normalize')
vim.api.nvim_buf_set_keymap(normalize_buf, 't', keys, '<Plug>(cmp.utils.keymap.normalize)', {})
for _, map in ipairs(vim.api.nvim_buf_get_keymap(normalize_buf, 't')) do
if keymap.t(map.rhs) == keymap.t('<Plug>(cmp.utils.keymap.normalize)') then
vim.api.nvim_buf_del_keymap(normalize_buf, 't', keys)
return map.lhs
end
local t = string.gsub(keys, "<([A-Za-z0-9\\%-%[%]%^@;,:_']-)>", function(match)
-- Use the \<* notation, which distinguishes <C-J> from <NL>, etc.
return vim.api.nvim_eval(string.format([["\<*%s>"]], match))
end)
return vim.fn.keytrans(t)
end or function(keys)
local normalize_buf = buffer.ensure('cmp.util.keymap.normalize')
vim.api.nvim_buf_set_keymap(normalize_buf, 't', keys, '<Plug>(cmp.utils.keymap.normalize)', {})
for _, map in ipairs(vim.api.nvim_buf_get_keymap(normalize_buf, 't')) do
if keymap.t(map.rhs) == keymap.t('<Plug>(cmp.utils.keymap.normalize)') then
vim.api.nvim_buf_del_keymap(normalize_buf, 't', keys)
return map.lhs
end
vim.api.nvim_buf_del_keymap(normalize_buf, 't', keys)
vim.api.nvim_buf_delete(normalize_buf, {})
return keys
end
vim.api.nvim_buf_del_keymap(normalize_buf, 't', keys)
vim.api.nvim_buf_delete(normalize_buf, {})
return keys
end

---Return vim notation keymapping (simple conversion).
---@param s string
Expand Down
1 change: 1 addition & 0 deletions lua/cmp/utils/keymap_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('keymap', function()
'<C-\\>',
'<C-;>',
'<C-,>',
'<C-.>',
'<C-:>',
'<C-_>',
"<C-'>",
Expand Down