diff options
-rw-r--r-- | runtime/doc/insert.txt | 4 | ||||
-rw-r--r-- | src/nvim/ops.c | 15 | ||||
-rw-r--r-- | test/old/testdir/test_normal.vim | 2 | ||||
-rw-r--r-- | test/old/testdir/test_registers.vim | 20 |
4 files changed, 37 insertions, 4 deletions
diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt index ce2ec36ca3..34affb22e9 100644 --- a/runtime/doc/insert.txt +++ b/runtime/doc/insert.txt @@ -160,22 +160,22 @@ CTRL-R CTRL-O {register} *i_CTRL-R_CTRL-O* auto-indent. Does the same as pasting with the mouse |<MiddleMouse>|. When the register is linewise this will insert the text above the current line, like with `P`. - Does not replace characters! The '.' register (last inserted text) is still inserted as typed. After this command, the '.' register contains the command typed and not the text. I.e., the literals "^R^O" and not the text from the register. + Does not replace characters in |Replace-mode|! CTRL-R CTRL-P {register} *i_CTRL-R_CTRL-P* Insert the contents of a register literally and fix the indent, like |[<MiddleMouse>|. - Does not replace characters! The '.' register (last inserted text) is still inserted as typed. After this command, the '.' register contains the command typed and not the text. I.e., the literals "^R^P" and not the text from the register. + Does not replace characters in |Replace-mode|! *i_CTRL-T* CTRL-T Insert one shiftwidth of indent at the start of the current diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8386dcaec6..32095177be 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1282,9 +1282,22 @@ int insert_reg(int regname, bool literally_arg) } else { for (size_t i = 0; i < reg->y_size; i++) { if (regname == '-') { + Direction dir = BACKWARD; + if ((State & REPLACE_FLAG) != 0) { + pos_T curpos; + u_save_cursor(); + del_bytes((colnr_T)strlen(reg->y_array[0]), true, false); + curpos = curwin->w_cursor; + if (oneright() == FAIL) { + // hit end of line, need to put forward (after the current position) + dir = FORWARD; + } + curwin->w_cursor = curpos; + } + AppendCharToRedobuff(Ctrl_R); AppendCharToRedobuff(regname); - do_put(regname, NULL, BACKWARD, 1, PUT_CURSEND); + do_put(regname, NULL, dir, 1, PUT_CURSEND); } else { stuffescaped(reg->y_array[i], literally); } diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim index 1c49c0b446..c72d83fa52 100644 --- a/test/old/testdir/test_normal.vim +++ b/test/old/testdir/test_normal.vim @@ -4186,4 +4186,4 @@ func Test_brace_single_line() bw! endfunc -" vim: shiftwidth=2 sts=2 expandtab +" vim: shiftwidth=2 sts=2 expandtab nofoldenable diff --git a/test/old/testdir/test_registers.vim b/test/old/testdir/test_registers.vim index 64dcc687ce..7cc5ebbe6f 100644 --- a/test/old/testdir/test_registers.vim +++ b/test/old/testdir/test_registers.vim @@ -890,4 +890,24 @@ func Test_register_y_append_reset() bwipe! endfunc +func Test_insert_small_delete_replace_mode() + new + call setline(1, ['foo', 'bar', 'foobar', 'bar']) + let @-='foo' + call cursor(2, 1) + exe ":norm! R\<C-R>-\<C-R>-" + call assert_equal('foofoo', getline(2)) + call cursor(3, 1) + norm! D + call assert_equal(['foo', 'foofoo', '', 'bar'], getline(1, 4)) + call cursor(4, 2) + exe ":norm! R\<C-R>-ZZZZ" + call assert_equal(['foo', 'foofoo', '', 'bfoobarZZZZ'], getline(1, 4)) + call cursor(1, 1) + let @-='' + exe ":norm! R\<C-R>-ZZZ" + call assert_equal(['ZZZ', 'foofoo', '', 'bfoobarZZZZ'], getline(1, 4)) + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab |