From 1a1a232e4a78d5ab3eb55978606db9a6dc4e78b8 Mon Sep 17 00:00:00 2001 From: Nicholas Todoroff Date: Tue, 29 Aug 2023 00:33:12 -0600 Subject: Escape special keys in mappings using backslash * Interpret a string like "\" as representing the literal key sequence '<' 'C' '-' 'R' '>'. * Add a '' special key so that e.g. the string "" is interpreted as the key sequence '\' followed by CTRL-R. --- doc/neovimb.1 | 6 ++++++ src/map.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/doc/neovimb.1 b/doc/neovimb.1 index 505b10b..fa3f888 100644 --- a/doc/neovimb.1 +++ b/doc/neovimb.1 @@ -566,6 +566,9 @@ number of keys have no visual representation, a special notation is required. As special key names have the format \fI<...>\fP. The following special keys can be used: , , , for the cursor keys, , , , , , - and -. +If you want an actual sequence of keys like "<", "C", "R", ">" then +escape with a backslash: "\". If you want a backslash followed by a special +key then use . .TP .PD 0 .BI ":nm[ap] {" lhs "} {" rhs } @@ -1537,6 +1540,9 @@ it might change the behaviour by adding or changing mappings. .IP ":set x-hint-command=:sh! curl -e % ;" This fills the inputbox with the prefilled download command and replaces `%' with the current URI and `;' with the URI of the hinted element. +.IP ":nnoremap ;f :set x-hint-command=:sh! firefox '\;\;x" +This makes the key sequence ";f" start hinting and then open the hinted URI in +firefox. .PD .RE .TP diff --git a/src/map.c b/src/map.c index e7129c0..12802d6 100644 --- a/src/map.c +++ b/src/map.c @@ -79,6 +79,7 @@ static struct { char *ch; int chlen; } key_labels[] = { + {"", 8, "\\", 1}, {"", 4, "\x0d", 1}, {"", 5, "\t", 1}, {"", 7, CSI_STR "kB", 3}, @@ -435,6 +436,15 @@ static char *convert_keys(const char *in, int inlen, int *len) *len = 0; for (p = in; p < &in[inlen]; p++) { + /* if we encounter the sequence \< we replace it with just < but act + * like it's a non-special character */ + if (*p == '\\' && p+1 < &in[inlen] && *(p+1) == '<') { + g_string_append_len(str, p+1, 1); + *len += 1; + ++p; + continue; + } + /* if it starts not with < we can add it literally */ if (*p != '<') { g_string_append_len(str, p, 1); -- cgit v1.2.3