From 86c2adc07463e37a60801e8fd0572402a5d27262 Mon Sep 17 00:00:00 2001 From: Matthew Malcomson Date: Fri, 10 Feb 2017 15:58:45 +0000 Subject: [PATCH] edit.c: CTRL-SPC: Insert previously-inserted text. #6090 Default Vim behavior of i_CTRL- is to insert the last-inserted text and exit insert mode. :help i_CTRL-@ Before this commit that did not happen because insert_handle_key() checks for NUL instead of checking for ' ' with a CTRL `mod_mask`. I'm leaving the check for NUL despite the fact that at the moment that key is never seen when using the terminal UI (not for C-Space, nor C-@). This is because I assume it's still allowed for other front-ends to pass NUL, but at the moment the terminal UI isn't. --- src/nvim/edit.c | 5 +++++ test/functional/insert/last_inserted_spec.lua | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/functional/insert/last_inserted_spec.lua diff --git a/src/nvim/edit.c b/src/nvim/edit.c index ecc794fb14..0de8177467 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -844,6 +844,11 @@ static int insert_handle_key(InsertState *s) return 0; // exit insert mode + case ' ': + if (mod_mask != 4) { + goto normalchar; + } + // FALLTHROUGH case K_ZERO: // Insert the previously inserted text. case NUL: case Ctrl_A: diff --git a/test/functional/insert/last_inserted_spec.lua b/test/functional/insert/last_inserted_spec.lua new file mode 100644 index 0000000000..dce23a3790 --- /dev/null +++ b/test/functional/insert/last_inserted_spec.lua @@ -0,0 +1,22 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert +local expect = helpers.expect + +clear() + +describe('insert-mode', function() + it('CTRL-@ inserts last-inserted text, leaves insert-mode', function() + insert('hello') + feed('ix') + expect('hellhello') + end) + -- C-Space is the same as C-@ + it('CTRL-SPC inserts last-inserted text, leaves insert-mode', function() + feed('ix') + expect('hellhellhello') + end) + it('CTRL-A inserts last inserted text', function() + feed('ix') + expect('hellhellhellhelloxo') + end) +end)