From 1e728837b3d73f955c522cb5ff9829c8f0946bc4 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 20 Mar 2019 17:01:14 -0700 Subject: [PATCH 1/2] Test of key_map(mode=INSERT_MODE) This shows that there is some problems with key_map for INSERT_MODE. Unfortunately, the unittests fail in a different way than when I attempt to do the same thing in my .vimrc.... --- tests.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests.py b/tests.py index fab6355..93d11b4 100644 --- a/tests.py +++ b/tests.py @@ -439,6 +439,17 @@ def process(stuff): self.assertEqual(output, "quick") self.assertEqual(changed, "The really fast brown fox jumps over the lazy dog") + def test_insert_key_map(self): + script = r""" +@key_map("a", mode=INSERT_MODE) +def change_words_and_move(): + replace_word('Test') + keys('1w') + +keys("aaaa") +""" + changed, output = run_vim(script, self.sample_text) + self.assertEqual(changed, "Test Test Test Test jumps over the lazy dog") class OptionsTests(VimTests): From 354b41eba3eaad523b8b280e6238c6cde52e692a Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 20 Mar 2019 17:02:52 -0700 Subject: [PATCH 2/2] Fix problem with insert_mode key_maps This fixes the problem I see when I attempt to write an insert mode key map in my .vimrc.py. That problem is that the text of the map ( :python3 snake.dispatch_mapped_function(140292554737728) ) is inserted into the buffer instead of leaving insert mode, running the text of the map, and then returning to insert mode. --- plugin/snake/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/snake/__init__.py b/plugin/snake/__init__.py index 13ee227..f146505 100644 --- a/plugin/snake/__init__.py +++ b/plugin/snake/__init__.py @@ -456,7 +456,10 @@ def wrapped(): fn = wrapped call = register_fn(fn) - command("%s %s :%s %s" % (map_command, key, PYTHON_CMD, call)) + if mode == INSERT_MODE: + command("%s %s :%s %s" % (map_command, key, PYTHON_CMD, call)) + else: + command("%s %s :%s %s" % (map_command, key, PYTHON_CMD, call)) else: command("%s %s %s" % (map_command, key, maybe_fn))