From 2b2a90051ebe53b5319304c87b5fae4480820c65 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 30 Mar 2025 07:12:01 +0800 Subject: [PATCH] fix(api): use E226 instead of E227 for duplicate abbreviation (#33159) (cherry picked from commit 99529577cc9f5229cbb3dac8ab4782bd43094102) --- src/nvim/mapping.c | 4 +++- test/functional/api/keymap_spec.lua | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 147985377e..3dc66f7dba 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -2804,7 +2804,9 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod api_set_error(err, kErrorTypeException, e_nomap, 0); goto fail_and_free; case 5: - api_set_error(err, kErrorTypeException, e_mapping_already_exists_for_str, lhs.data); + api_set_error(err, kErrorTypeException, + is_abbrev ? e_abbreviation_already_exists_for_str + : e_mapping_already_exists_for_str, lhs.data); goto fail_and_free; default: assert(false && "Unrecognized return code!"); diff --git a/test/functional/api/keymap_spec.lua b/test/functional/api/keymap_spec.lua index 73dae0dd60..acaccee4e5 100644 --- a/test/functional/api/keymap_spec.lua +++ b/test/functional/api/keymap_spec.lua @@ -814,6 +814,12 @@ describe('nvim_set_keymap, nvim_del_keymap', function() 'E227: Mapping already exists for ', pcall_err(api.nvim_set_keymap, 'n', '', 'rhs', { unique = true }) ) + + api.nvim_set_keymap('ia', 'lhs', 'rhs', {}) + eq( + 'E226: Abbreviation already exists for lhs', + pcall_err(api.nvim_set_keymap, 'ia', 'lhs', 'rhs', { unique = true }) + ) end) it('can set mappings whose RHS change dynamically', function()