From 87ddae9ebd8b1ff5ad0b0d3a1d1d674e31dc96d6 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Sat, 14 Feb 2015 21:41:33 +0100 Subject: [PATCH] Add as special map key name (#176). Normally the literal space char ' ' can be used for mappings. In case this is part of the lhs it can be given escaped by '\'. But this does not work on the rhs, because there is no evaluation of escaping for space like in vim. On the other hand the rhs starts with the first none whitespace char after the lhs. So it wasn't possible to apply mapping to sequences that starts with one or more spaces. This patch adds the new special key name '' to be used in this cases. --- doc/vimb.1 | 7 +++++-- src/map.c | 1 + tests/test-map.c | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/vimb.1 b/doc/vimb.1 index 8c353f2..b7dbce8 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -476,11 +476,14 @@ configured 'home-page' is opened. Key mappings allow to alter actions of key presses. Each key mapping is associated with a mode and only has effect when the mode is active. Following commands allow the user to substitute one sequence of key presses by another. - +.TP .BI Syntax: " :{m}map {lhs} {rhs}" Note that the \fIlhs\fP ends with the first found space. If you want to use space also in the {lhs} you have to escape this with a single `\\' like shown in the examples. +.br +The \fIrhs\fP starts with the first none space char. If you want a \fIrhs\fP +that starts with a space, you have to use "". .RS 0 .TP .PD 0 @@ -501,7 +504,7 @@ special notation is required. As special key names have the format \fI<...>\fP. Following special keys can be used , , , for the cursor keys, , , , -- and -. +, - and -. .TP .BI ":nm[ap] {" lhs "} {" rhs } .TP diff --git a/src/map.c b/src/map.c index 12c3f4d..123ede9 100644 --- a/src/map.c +++ b/src/map.c @@ -93,6 +93,7 @@ static struct { {"", 5, "\t", 1}, {"", 7, CSI_STR "kB", 3}, {"", 5, "\x1b", 1}, + {"", 7, "\x20", 1}, {"", 4, CSI_STR "ku", 3}, {"", 6, CSI_STR "kd", 3}, {"", 6, CSI_STR "kl", 3}, diff --git a/tests/test-map.c b/tests/test-map.c index 2333d54..e0a66b5 100644 --- a/tests/test-map.c +++ b/tests/test-map.c @@ -56,6 +56,7 @@ static void test_handle_string_simple(void) ASSERT_MAPPING("a", "[a]"); ASSERT_MAPPING("b", "[b]"); ASSERT_MAPPING("[c]", "c"); + ASSERT_MAPPING("d", " [d]"); ASSERT_MAPPING("", "[tab]"); ASSERT_MAPPING("", "[shift-tab]"); ASSERT_MAPPING("", "[ctrl-f]"); @@ -162,6 +163,7 @@ int main(int argc, char *argv[]) /* add some mappings to test */ map_insert("a", "[a]", 't', false); /* inlen < mappedlen */ map_insert("b", "[b]", 't', false); + map_insert("d", "[d]", 't', false); map_insert("[c]", "c", 't', false); /* inlen > mappedlen */ map_insert("foobar", "[baz]", 't', false); map_insert("", "[tab]", 't', false); -- 2.20.1