diff options
-rw-r--r-- | runtime/doc/vim_diff.txt | 3 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 6 | ||||
-rw-r--r-- | src/nvim/ops.c | 13 | ||||
-rw-r--r-- | test/functional/cmdline/ctrl_r_spec.lua | 34 | ||||
-rw-r--r-- | test/functional/cmdline/history_spec.lua (renamed from test/functional/ex_getln/history_spec.lua) | 0 |
5 files changed, 46 insertions, 10 deletions
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index eeb5e85036..7fbd957a22 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -238,6 +238,9 @@ 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 the |cmdline| separates lines +by <Space> instead of <CR>. + ============================================================================== 5. Missing legacy features *nvim-features-missing* *if_lua* *if_perl* *if_mzscheme* *if_tcl* diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index d99c8d02f7..2a4fc067db 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2471,10 +2471,10 @@ void restore_cmdline_alloc(char_u *p) /// /// @param regname Register name. /// @param literally Insert text literally instead of "as typed". -/// @param remcr When true, remove trailing CR. +/// @param remspc When true, remove trailing <Space>. /// /// @returns FAIL for failure, OK otherwise -static bool cmdline_paste(int regname, bool literally, bool remcr) +static bool cmdline_paste(int regname, bool literally, bool remspc) { long i; char_u *arg; @@ -2539,7 +2539,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) return OK; } - return cmdline_paste_reg(regname, literally, remcr); + return cmdline_paste_reg(regname, literally, remspc); } /* diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d58c8700ca..2f45795812 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1260,16 +1260,16 @@ 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. /// /// @param regname Register name. /// @param literally Insert text literally instead of "as typed". -/// @param remcr When true, don't add CR characters. +/// @param remspc When true, don't add <Space> characters. /// /// @returns FAIL for failure, OK otherwise -bool cmdline_paste_reg(int regname, bool literally, bool remcr) +bool cmdline_paste_reg(int regname, bool literally, bool remspc) { yankreg_T *reg = get_yank_register(regname, YREG_PASTE); if (reg->y_array == NULL) @@ -1278,10 +1278,9 @@ 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) { - cmdline_paste_str((char_u *)"\r", literally); + // Insert space between lines, unless `remspc` is true. + if (i < reg->y_size - 1 && !remspc) { + cmdline_paste_str((char_u *)" ", literally); } /* Check for CTRL-C, in case someone tries to paste a few thousand diff --git a/test/functional/cmdline/ctrl_r_spec.lua b/test/functional/cmdline/ctrl_r_spec.lua new file mode 100644 index 0000000000..1bb3174737 --- /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 <Space> between lines', function() + insert([[ + line1abc + line2somemoretext + ]]) + -- Yank 2 lines linewise, then paste to cmdline. + feed([[<C-\><C-N>gg0yj:<C-R>0]]) + -- <Space> inserted *between* lines, not after the final line. + eq('line1abc line2somemoretext', funcs.getcmdline()) + + -- Yank 2 lines characterwise, then paste to cmdline. + feed([[<C-\><C-N>gg05lyvj:<C-R>0]]) + -- <Space> inserted *between* lines, not after the final line. + eq('abc line2', funcs.getcmdline()) + + -- Yank 1 line linewise, then paste to cmdline. + feed([[<C-\><C-N>ggyy:<C-R>0]]) + -- No spaces inserted. + eq('line1abc', funcs.getcmdline()) + end) + + it('pasting special register inserts <CR>, <NL>', function() + feed([[:<C-R>="foo\nbar\rbaz"<CR>]]) + 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 index 20f9cf06a2..20f9cf06a2 100644 --- a/test/functional/ex_getln/history_spec.lua +++ b/test/functional/cmdline/history_spec.lua |