aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-07-14 08:17:49 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-07-14 13:39:40 +0800
commitba36742211eea55bed2ffbca129a45023967f204 (patch)
tree788badd75a8c8f673a0f4fa7e498112320388f01
parent9093fbdd026f088d923fea374a96a8b01ca0df3a (diff)
downloadrneovim-ba36742211eea55bed2ffbca129a45023967f204.tar.gz
rneovim-ba36742211eea55bed2ffbca129a45023967f204.tar.bz2
rneovim-ba36742211eea55bed2ffbca129a45023967f204.zip
vim-patch:9.1.0574: ex: wrong handling of commands after bar
Problem: ex: wrong handling of commands after bar Solution: for :append, :insert and :change use the text after the bar as input for those commands. This is what POSIX requests. (Mohamed Akram) See the POSIX Spec: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ex.html#tag_20_40_13_03 Section 12.c closes: vim/vim#15229 https://github.com/vim/vim/commit/8c446da34998f6350911e07fbfd7932412c83185 Co-authored-by: Mohamed Akram <mohd.akram@outlook.com>
-rw-r--r--runtime/doc/insert.txt10
-rw-r--r--src/nvim/ex_cmds.c6
-rw-r--r--src/nvim/ex_docmd.c7
-rw-r--r--test/old/testdir/test_ex_mode.vim8
4 files changed, 29 insertions, 2 deletions
diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt
index 6eda76f239..e12f240430 100644
--- a/runtime/doc/insert.txt
+++ b/runtime/doc/insert.txt
@@ -1927,6 +1927,16 @@ These two commands will keep on asking for lines, until you type a line
containing only a ".". Watch out for lines starting with a backslash, see
|line-continuation|.
+Text typed after a "|" command separator is used first. So the following
+command in ex mode: >
+ :a|one
+ two
+ .
+ :visual
+<appends the following text, after the cursor line: >
+ one
+ two
+<
NOTE: These commands cannot be used with |:global| or |:vglobal|.
":append" and ":insert" don't work properly in between ":if" and
":endif", ":for" and ":endfor", ":while" and ":endwhile".
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 0aa897105e..e4e9075afa 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -2784,7 +2784,11 @@ void ex_append(exarg_T *eap)
indent = get_indent_lnum(lnum);
}
}
- if (eap->ea_getline == NULL) {
+ if (*eap->arg == '|') {
+ // Get the text after the trailing bar.
+ theline = xstrdup(eap->arg + 1);
+ *eap->arg = NUL;
+ } else if (eap->ea_getline == NULL) {
// No getline() function, use the lines that follow. This ends
// when there is no more.
if (eap->nextcmd == NULL || *eap->nextcmd == NUL) {
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 6fae8f091e..1d20829d3c 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -4108,7 +4108,12 @@ void separate_nextcmd(exarg_T *eap)
&& !(eap->argt & EX_NOTRLCOM)
&& (eap->cmdidx != CMD_at || p != eap->arg)
&& (eap->cmdidx != CMD_redir
- || p != eap->arg + 1 || p[-1] != '@')) || *p == '|' || *p == '\n') {
+ || p != eap->arg + 1 || p[-1] != '@'))
+ || (*p == '|'
+ && eap->cmdidx != CMD_append
+ && eap->cmdidx != CMD_change
+ && eap->cmdidx != CMD_insert)
+ || *p == '\n') {
// We remove the '\' before the '|', unless EX_CTRLV is used
// AND 'b' is present in 'cpoptions'.
if ((vim_strchr(p_cpo, CPO_BAR) == NULL
diff --git a/test/old/testdir/test_ex_mode.vim b/test/old/testdir/test_ex_mode.vim
index 31615ec47d..622a591c98 100644
--- a/test/old/testdir/test_ex_mode.vim
+++ b/test/old/testdir/test_ex_mode.vim
@@ -293,4 +293,12 @@ func Test_implicit_print()
bw!
endfunc
+" Test inserting text after the trailing bar
+func Test_insert_after_trailing_bar()
+ new
+ call feedkeys("Qi|\nfoo\n.\na|bar\nbar\n.\nc|baz\n.", "xt")
+ call assert_equal(['', 'foo', 'bar', 'baz'], getline(1, '$'))
+ bwipe!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab