summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-09-24 12:50:45 +0100
committerBram Moolenaar <Bram@vim.org>2022-09-24 12:50:45 +0100
commit5939c357431f8e43853ad80b03303167f39763df (patch)
tree208c6db52b178a1138a17bcbce4cc854d94348f1 /src
parente9dcf13a3007d4f603e007e0526b0005fd026bc5 (diff)
patch 9.0.0569: cannot easily get out when using "vim file | grep word"v9.0.0569
Problem: Cannot easily get out when using "vim file | grep word". Solution: Without changes let CTRL-C exit Vim. Otherwise give a message on stderr. (closes #11209)
Diffstat (limited to 'src')
-rw-r--r--src/normal.c27
-rw-r--r--src/testdir/test_startup.vim23
-rw-r--r--src/version.c2
3 files changed, 50 insertions, 2 deletions
diff --git a/src/normal.c b/src/normal.c
index 35f7610c31..be578ae27e 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -6793,10 +6793,33 @@ nv_esc(cmdarg_T *cap)
&& !VIsual_active
&& no_reason)
{
+ int out_redir = !stdout_isatty
+#ifdef FEAT_GUI
+ && !gui.in_use
+#endif
+ ;
+ // The user may accidentally do "vim file | grep word" and then
+ // CTRL-C doesn't show anything. With a changed buffer give the
+ // message on stderr. Without any changes might as well exit.
if (anyBufIsChanged())
- msg(_("Type :qa! and press <Enter> to abandon all changes and exit Vim"));
+ {
+ char *ms = _("Type :qa! and press <Enter> to abandon all changes and exit Vim");
+
+ if (out_redir)
+ mch_errmsg(ms);
+ else
+ msg(ms);
+ }
else
- msg(_("Type :qa and press <Enter> to exit Vim"));
+ {
+ if (out_redir)
+ {
+ got_int = FALSE;
+ do_cmdline_cmd((char_u *)"qa");
+ }
+ else
+ msg(_("Type :qa and press <Enter> to exit Vim"));
+ }
}
if (restart_edit != 0)
diff --git a/src/testdir/test_startup.vim b/src/testdir/test_startup.vim
index 6cc62ad015..7995cd2e5b 100644
--- a/src/testdir/test_startup.vim
+++ b/src/testdir/test_startup.vim
@@ -1109,6 +1109,29 @@ func Test_not_a_term()
call delete('Xvimout')
endfunc
+" Test quitting with CTRL-C when output is redirected.
+func Test_redirect_Ctrl_C()
+ CheckUnix
+ CheckNotGui
+ CheckRunVimInTerminal
+
+ let buf = Run_shell_in_terminal({})
+ " Wait for the shell to display a prompt
+ call WaitForAssert({-> assert_notequal('', term_getline(buf, 1))})
+
+ call term_sendkeys(buf, GetVimProg() .. " | grep word\<CR>")
+ call WaitForAssert({-> assert_match("Output is not to a terminal", getline(1, 4)->join())})
+ " wait for the hard coded delay, otherwise the CTRL-C interrupts startup
+ sleep 2
+ call term_sendkeys(buf, "\<C-C>")
+ sleep 100m
+ call term_sendkeys(buf, "exit\<CR>")
+ call WaitForAssert({-> assert_equal('dead', job_status(g:job))})
+
+ exe buf . 'bwipe!'
+ unlet g:job
+endfunc
+
" Test for the "-w scriptout" argument
func Test_w_arg()
diff --git a/src/version.c b/src/version.c
index e8d6253e09..09b05187ea 100644
--- a/src/version.c
+++ b/src/version.c
@@ -700,6 +700,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 569,
+/**/
568,
/**/
567,