mirror of
https://github.com/neovim/neovim.git
synced 2025-09-25 12:38:33 +00:00
cmdline: CTRL-R: <Space> instead of CR between lines.
^M isn't any more "correct" than space: the "technically correct" interpretation is to execute the first line that is seen (and this is what happens on middle-click paste in Vim). ^M is only intended to defuse the newline, so that the user can review the command. We can do that with a space instead, and then the command can be executed without having to fix it up first.
This commit is contained in:
@@ -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
|
coerced to strings. See |id()| for more details, currently it uses
|
||||||
`printf("%p", {expr})` internally.
|
`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*
|
5. Missing legacy features *nvim-features-missing*
|
||||||
*if_lua* *if_perl* *if_mzscheme* *if_tcl*
|
*if_lua* *if_perl* *if_mzscheme* *if_tcl*
|
||||||
|
@@ -2471,10 +2471,10 @@ void restore_cmdline_alloc(char_u *p)
|
|||||||
///
|
///
|
||||||
/// @param regname Register name.
|
/// @param regname Register name.
|
||||||
/// @param literally Insert text literally instead of "as typed".
|
/// @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
|
/// @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;
|
long i;
|
||||||
char_u *arg;
|
char_u *arg;
|
||||||
@@ -2539,7 +2539,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmdline_paste_reg(regname, literally, remcr);
|
return cmdline_paste_reg(regname, literally, remspc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -1260,16 +1260,16 @@ int get_spec_reg(
|
|||||||
|
|
||||||
/// Paste a yank register into the command line.
|
/// Paste a yank register into the command line.
|
||||||
/// Only for non-special registers.
|
/// 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
|
/// insert_reg() can't be used here, because special characters from the
|
||||||
/// register contents will be interpreted as commands.
|
/// register contents will be interpreted as commands.
|
||||||
///
|
///
|
||||||
/// @param regname Register name.
|
/// @param regname Register name.
|
||||||
/// @param literally Insert text literally instead of "as typed".
|
/// @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
|
/// @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);
|
yankreg_T *reg = get_yank_register(regname, YREG_PASTE);
|
||||||
if (reg->y_array == NULL)
|
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++) {
|
for (size_t i = 0; i < reg->y_size; i++) {
|
||||||
cmdline_paste_str(reg->y_array[i], literally);
|
cmdline_paste_str(reg->y_array[i], literally);
|
||||||
|
|
||||||
// Insert ^M between lines and after last line if type is kMTLineWise.
|
// Insert space between lines, unless `remspc` is true.
|
||||||
// Don't do this when "remcr" is true.
|
if (i < reg->y_size - 1 && !remspc) {
|
||||||
if ((reg->y_type == kMTLineWise || i < reg->y_size - 1) && !remcr) {
|
cmdline_paste_str((char_u *)" ", literally);
|
||||||
cmdline_paste_str((char_u *)"\r", literally);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for CTRL-C, in case someone tries to paste a few thousand
|
/* Check for CTRL-C, in case someone tries to paste a few thousand
|
||||||
|
34
test/functional/cmdline/ctrl_r_spec.lua
Normal file
34
test/functional/cmdline/ctrl_r_spec.lua
Normal file
@@ -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)
|
||||||
|
|
Reference in New Issue
Block a user