diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 176a29d072..bcc5d03ff0 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -238,6 +238,8 @@ newly allocated memory all over the place) and fail on types which cannot be coerced to strings. See |id()| for more details, currently it uses `printf("%p", {expr})` internally. +|c_CTRL-R| pasting a non-special register into |cmdline| omits the last . + ============================================================================== 5. Missing legacy features *nvim-features-missing* *if_lua* *if_perl* *if_mzscheme* *if_tcl* diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d58c8700ca..8bfda3c193 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1260,7 +1260,7 @@ int get_spec_reg( /// Paste a yank register into the command line. /// Only for non-special registers. -/// Used by CTRL-R command in command-line mode +/// Used by CTRL-R in command-line mode. /// insert_reg() can't be used here, because special characters from the /// register contents will be interpreted as commands. /// @@ -1278,9 +1278,8 @@ bool cmdline_paste_reg(int regname, bool literally, bool remcr) for (size_t i = 0; i < reg->y_size; i++) { cmdline_paste_str(reg->y_array[i], literally); - // Insert ^M between lines and after last line if type is kMTLineWise. - // Don't do this when "remcr" is true. - if ((reg->y_type == kMTLineWise || i < reg->y_size - 1) && !remcr) { + // Insert ^M between lines, unless `remcr` is true. + if (i < reg->y_size - 1 && !remcr) { cmdline_paste_str((char_u *)"\r", literally); } diff --git a/test/functional/cmdline/ctrl_r_spec.lua b/test/functional/cmdline/ctrl_r_spec.lua new file mode 100644 index 0000000000..d2dad23e98 --- /dev/null +++ b/test/functional/cmdline/ctrl_r_spec.lua @@ -0,0 +1,34 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear, insert, funcs, eq, feed = + helpers.clear, helpers.insert, helpers.funcs, helpers.eq, helpers.feed + +describe('cmdline CTRL-R', function() + before_each(clear) + + it('pasting non-special register inserts *between* lines', function() + insert([[ + line1abc + line2somemoretext + ]]) + -- Yank 2 lines linewise, then paste to cmdline. + feed([[gg0yj:0]]) + -- inserted between lines, NOT after the final line. + eq('line1abc\rline2somemoretext', funcs.getcmdline()) + + -- Yank 2 lines characterwise, then paste to cmdline. + feed([[gg05lyvj:0]]) + -- inserted between lines, NOT after the final line. + eq('abc\rline2', funcs.getcmdline()) + + -- Yank 1 line linewise, then paste to cmdline. + feed([[ggyy:0]]) + -- No inserted. + eq('line1abc', funcs.getcmdline()) + end) + + it('pasting special register inserts , ', function() + feed([[:="foo\nbar\rbaz"]]) + eq('foo\nbar\rbaz', funcs.getcmdline()) + end) +end) + diff --git a/test/functional/ex_getln/history_spec.lua b/test/functional/cmdline/history_spec.lua similarity index 100% rename from test/functional/ex_getln/history_spec.lua rename to test/functional/cmdline/history_spec.lua