Add <Space> as special map key name (#176).
authorDaniel Carl <danielcarl@gmx.de>
Sat, 14 Feb 2015 20:41:33 +0000 (21:41 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sat, 14 Feb 2015 20:56:10 +0000 (21:56 +0100)
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 '<Space>' to be used in this cases.

doc/vimb.1
src/map.c
tests/test-map.c

index 8c353f2..b7dbce8 100644 (file)
@@ -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 "<Space>".
 .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 <Left>, <Up>, <Right>, <Down> for the cursor keys, <Tab>, <Esc>, <CR>,
-<F1>-<F12> and <C-A>-<C-Z>.
+<Space>, <F1>-<F12> and <C-A>-<C-Z>.
 .TP
 .BI ":nm[ap] {" lhs "} {" rhs }
 .TP
index 12c3f4d..123ede9 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -93,6 +93,7 @@ static struct {
     {"<Tab>",   5, "\t",         1},
     {"<S-Tab>", 7, CSI_STR "kB", 3},
     {"<Esc>",   5, "\x1b",       1},
+    {"<Space>", 7, "\x20",       1},
     {"<Up>",    4, CSI_STR "ku", 3},
     {"<Down>",  6, CSI_STR "kd", 3},
     {"<Left>",  6, CSI_STR "kl", 3},
index 2333d54..e0a66b5 100644 (file)
@@ -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>", "[tab]");
     ASSERT_MAPPING("<S-Tab>", "[shift-tab]");
     ASSERT_MAPPING("<C-F>", "[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", "<Space>[d]", 't', false);
     map_insert("[c]", "c", 't', false);         /* inlen > mappedlen  */
     map_insert("foobar", "[baz]", 't', false);
     map_insert("<Tab>", "[tab]", 't', false);