diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index c9b8763354..a922d42b1f 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -628,17 +628,24 @@ static int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, // vi-compatible way. int same = -1; - const int first = vim_iswordp(lhs); + const char *p = lhs; + const char *p_char = mb_unescape(&p); + if (p_char == NULL) { + p_char = p++; + } + const int first = vim_iswordp(p_char); int last = first; - const char *p = lhs + utfc_ptr2len(lhs); int n = 1; while (p < lhs + len) { n++; // nr of (multi-byte) chars - last = vim_iswordp(p); // type of last char + p_char = mb_unescape(&p); + if (p_char == NULL) { + p_char = p++; + } + last = vim_iswordp(p_char); // type of last char if (same == -1 && last != first) { same = n - 1; // count of same char type } - p += utfc_ptr2len(p); } if (last && n > 2 && same >= 0 && same < n - 1) { retval = 1; diff --git a/test/old/testdir/test_mapping.vim b/test/old/testdir/test_mapping.vim index 2c6730bfed..78ff9850ab 100644 --- a/test/old/testdir/test_mapping.vim +++ b/test/old/testdir/test_mapping.vim @@ -7,11 +7,29 @@ source term_util.vim func Test_abbreviation() new - " abbreviation with 0x80 should work + + " abbreviation with 0x80 (full-id) inoreab чкпр vim call feedkeys("Goчкпр \", "xt") call assert_equal('vim ', getline('$')) iunab чкпр + + " abbreviation with 0x80 (non-id) + inoreab abc⁀ abc^ + inoreab ⁀ ^ + call feedkeys("Goabc⁀ def⁀ ⁀ \", "xt") + call assert_equal('abc^ def⁀ ^ ', getline('$')) + iunab abc⁀ + iunab ⁀ + + " abbreviation with 0x9b (non-id) + inoreab abc; abc; + inoreab ; ; + call feedkeys("Goabc; def; ; \", "xt") + call assert_equal('abc; def; ; ', getline('$')) + iunab abc; + iunab ; + bwipe! endfunc