diff options
-rw-r--r-- | src/nvim/edit.c | 9 | ||||
-rw-r--r-- | test/old/testdir/test_put.vim | 27 |
2 files changed, 32 insertions, 4 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index f5e40d0491..a81d1416f1 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2708,20 +2708,21 @@ int stuff_inserted(int c, int count, int no_esc) } if (insert->size > 0) { - char *p; // look for the last ESC in 'insert' - for (p = insert->data + (insert->size - 1); p >= insert->data; p--) { + for (char *p = insert->data + insert->size - 1; p >= insert->data; p--) { if (*p == ESC) { insert->size = (size_t)(p - insert->data); break; } } + } + if (insert->size > 0) { + char *p = insert->data + insert->size - 1; // when the last char is either "0" or "^" it will be quoted if no ESC // comes after it OR if it will inserted more than once and "ptr" // starts with ^D. -- Acevedo - if (p >= insert->data - && (*p == '0' || *p == '^') + if ((*p == '0' || *p == '^') && (no_esc || (*insert->data == Ctrl_D && count > 1))) { last = *p; insert->size--; diff --git a/test/old/testdir/test_put.vim b/test/old/testdir/test_put.vim index 6b332faaeb..e0a78c7409 100644 --- a/test/old/testdir/test_put.vim +++ b/test/old/testdir/test_put.vim @@ -328,4 +328,31 @@ func Test_put_list() bw! endfunc +" Test pasting the '.' register +func Test_put_inserted() + new + + for s in ['', '…', '0', '^', '+0', '+^', '…0', '…^'] + call setline(1, 'foobar') + exe $"normal! A{s}\<Esc>" + call assert_equal($'foobar{s}', getline(1)) + normal! ".p + call assert_equal($'foobar{s}{s}', getline(1)) + normal! ".2p + call assert_equal($'foobar{s}{s}{s}{s}', getline(1)) + endfor + + for s in ['0', '^', '+0', '+^', '…0', '…^'] + call setline(1, "\t\t\t\t\tfoobar") + exe $"normal! A\<C-D>{s}\<Esc>" + call assert_equal($"\t\t\t\tfoobar{s}", getline(1)) + normal! ".p + call assert_equal($"\t\t\tfoobar{s}{s}", getline(1)) + normal! ".2p + call assert_equal($"\tfoobar{s}{s}{s}{s}", getline(1)) + endfor + + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab |