]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0680: keytrans() doesn't replace '|' and '\' v9.2.0680
authorzeertzjq <zeertzjq@outlook.com>
Sat, 20 Jun 2026 16:38:47 +0000 (16:38 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 20 Jun 2026 16:38:47 +0000 (16:38 +0000)
Problem:  keytrans() doesn't replace '|' and '\' (user202729)
Solution: Replace '|' and '\' with "<Bar>" and "<Bslash>" respectively.
          (zeertzjq)

fixes:  #20585
closes: #20586

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/message.c
src/proto/message.pro
src/testdir/test_functions.vim
src/version.c

index ac25fe322ead555ac56e5244e612b4b3f329c69c..b0d09f6da6a4e55e92772d1fa28244c6bd33bb24 100644 (file)
@@ -1907,14 +1907,15 @@ str2special_save(
     char_u  *str,
     int            replace_spaces,     // TRUE to replace " " with "<Space>".
                                // used for the lhs of mapping and keytrans().
-    int            replace_lt)         // TRUE to replace "<" with "<lt>".
+    int            replace_others)     // TRUE to replace "<" with "<lt>",
+                               // "|" with "<Bar>", "\" with "<Bslash>".
 {
     garray_T   ga;
     char_u     *p = str;
 
     ga_init2(&ga, 1, 40);
     while (*p != NUL)
-       ga_concat(&ga, str2special(&p, replace_spaces, replace_lt));
+       ga_concat(&ga, str2special(&p, replace_spaces, replace_others));
     ga_append(&ga, NUL);
     return (char_u *)ga.ga_data;
 }
@@ -1931,7 +1932,8 @@ str2special(
     char_u     **sp,
     int                replace_spaces, // TRUE to replace " " with "<Space>".
                                // used for the lhs of mapping and keytrans().
-    int                replace_lt)     // TRUE to replace "<" with "<lt>".
+    int                replace_others) // TRUE to replace "<" with "<lt>",
+                               // "|" with "<Bar>", "\" with "<Bslash>".
 {
     int                        c;
     static char_u      buf[7];
@@ -1999,7 +2001,7 @@ str2special(
     if (special
        || c < ' '
        || (replace_spaces && c == ' ')
-       || (replace_lt && c == '<'))
+       || (replace_others && (c == '<' || c == '|' || c == '\\')))
        return get_special_key_name(c, modifiers);
     buf[0] = c;
     buf[1] = NUL;
index 34b381866f5909030b6d12a7403c58fa7166f00a..29519a2af6b83a9d282d4d39f2a93c07182dae8d 100644 (file)
@@ -38,8 +38,8 @@ char_u *msg_outtrans_one(char_u *p, int attr);
 int msg_outtrans_len_attr(char_u *msgstr, int len, int attr);
 void msg_make(char_u *arg);
 int msg_outtrans_special(char_u *strstart, int from, int maxlen);
-char_u *str2special_save(char_u *str, int replace_spaces, int replace_lt);
-char_u *str2special(char_u **sp, int replace_spaces, int replace_lt);
+char_u *str2special_save(char_u *str, int replace_spaces, int replace_others);
+char_u *str2special(char_u **sp, int replace_spaces, int replace_others);
 void str2specialbuf(char_u *sp, char_u *buf, int len);
 void msg_prt_line(char_u *s, int list);
 void msg_puts(char *s);
index 8ca73a62ae86a5c618296fa0f0f82d8aa9f38874..bace3800017b94765f0d7236896972ca2f467c9e 100644 (file)
@@ -3702,6 +3702,10 @@ func Test_keytrans()
   call assert_equal('<M-x>', "\<*M-x>"->keytrans())
   call assert_equal('<C-I>', "\<*C-I>"->keytrans())
   call assert_equal('<S-3>', "\<*S-3>"->keytrans())
+  call assert_equal('<Bar>', '|'->keytrans())
+  call assert_equal('<M-Bar>', "\<*M-|>"->keytrans())
+  call assert_equal('<Bslash>', '\'->keytrans())
+  call assert_equal('<M-Bslash>', "\<*M-\>"->keytrans())
   call assert_equal('π', 'π'->keytrans())
   call assert_equal('<M-π>', "\<M-π>"->keytrans())
   call assert_equal('ě', 'ě'->keytrans())
index 933e847377bd125822195c5545d74d3056e24e53..484f7515a9fcb1496220a3e62b5021047f28d8c8 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    680,
 /**/
     679,
 /**/