When output is not to terminal, how to kill vim easily?

9,750 views
Skip to first unread message

Yuri

unread,
Apr 11, 2015, 1:00:27 AM4/11/15
to vim_dev
Once in a while I get into this after accidentally typing the wrong command:
# vim some-file | some-cmd
bash: some-cmd: command not found
Vim: Warning: Output is not to a terminal
^C

Ctrl-C doesn't kill vim. So I have to press Ctrl-Z and then have to
either 'killall vim', or trying to determine what is the pid of vim to kill.
Is there any way to make it just die on Ctrl-C in such situation?

Thanks,
Yuri

Sergey Alyoshin

unread,
Apr 11, 2015, 3:06:24 AM4/11/15
to vim_dev
kill %1 after ctrl-z in bash.

Yuri

unread,
Apr 11, 2015, 4:00:28 AM4/11/15
to vim...@googlegroups.com
On 04/11/2015 00:06, Sergey Alyoshin wrote:
> kill %1 after ctrl-z in bash.

Why vim even starts when the output isn't a terminal? This "Warning:
Output is not to a terminal" should be the terminal error.
Usually text programs that print with colors fall back into non-colored
output mode, and vim is fully dependent on the terminal sequences, so it
should just fail.

Yuri

LCD 47

unread,
Apr 11, 2015, 7:59:06 AM4/11/15
to vim...@googlegroups.com
On 11 April 2015, Yuri <yu...@rawbw.com> wrote:
> On 04/11/2015 00:06, Sergey Alyoshin wrote:
> >kill %1 after ctrl-z in bash.
>
> Why vim even starts when the output isn't a terminal?

It's useful in various situations, such as batch runs, or debugging
raw escape sequences sent to the terminal.

> This "Warning: Output is not to a terminal" should be the terminal
> error. Usually text programs that print with colors fall back into
> non-colored output mode, and vim is fully dependent on the terminal
> sequences, so it should just fail.

/lcd

Yuri

unread,
Apr 11, 2015, 6:50:10 PM4/11/15
to vim...@googlegroups.com, Bram Moolenaar
On 04/11/2015 04:58, LCD 47 wrote:
> It's useful in various situations, such as batch runs, or debugging
> raw escape sequences sent to the terminal.


Since tolerance to non-terminal is something that obviously only a very
tiny fraction of users needs, I made this patch that makes such
tolerance a non-default behavior. New command line option
--allow-non-term enables the old behavior.

I think many fast-typing vim users will greatly appreciate such change.

Yuri
patch-yuri-vim-allow_non_term.patch

Nazri Ramliy

unread,
Apr 11, 2015, 10:32:14 PM4/11/15
to vim_dev, Bram Moolenaar
On Sun, Apr 12, 2015 at 6:50 AM, Yuri <yu...@rawbw.com> wrote:
> Since tolerance to non-terminal is something that obviously only a very tiny
> fraction of users needs, I made this patch that makes such tolerance a
> non-default behavior. New command line option --allow-non-term enables the
> old behavior.

This will break existing scripts that depend on the current default
behavior and that's not good.

You motivation for the patch is to work around accidentally typing
"vim some-file | some-cmd".
I do make the same mistake myself but I don't think this is good
enough reason for patching vim.

nazri.

Yuri

unread,
Apr 11, 2015, 11:28:11 PM4/11/15
to vim...@googlegroups.com, Bram Moolenaar
On 04/11/2015 19:32, Nazri Ramliy wrote:
> This will break existing scripts that depend on the current default
> behavior and that's not good.

What scripts are you talking about?

Yuri

Jürgen Krämer

unread,
Apr 13, 2015, 2:28:04 AM4/13/15
to vim...@googlegroups.com

Hi,
don't use Ctrl-C, just enter :q like you normally would.

Regards,
Jürgen

--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)

Yuri

unread,
Apr 13, 2015, 4:53:21 PM4/13/15
to vim...@googlegroups.com, Bram Moolenaar
On 04/11/2015 19:32, Nazri Ramliy wrote:
> This will break existing scripts that depend on the current default
> behavior and that's not good.
>
> You motivation for the patch is to work around accidentally typing
> "vim some-file | some-cmd".
> I do make the same mistake myself but I don't think this is good
> enough reason for patching vim.

In such case, we need to understand the following items:
* what are the scripts?
* what is the usage model?
* how many scripts there are?
* how many people run them?

I never heard about these scripts. If they provide some useful
functionality, I would like to run them too.
But if they are only for testing by some very limited number of users,
why not make everyone else's life easier and not have vim exhibit the
strange behavior?

Yuri
Message has been deleted

Chr. von Stuckrad

unread,
Apr 10, 2018, 4:07:27 AM4/10/18
to vim...@googlegroups.com
Not really, if the pipe makes vim run 'in background' and
having no normal connection to the terminal, it can not be
informed about the ^C.

As long as ONLY THE OUTPUT IS 'invisible', but the input still
is from the terminal, you can end vim normally by ':qa!' BUT
you need to hit <Ctrl-J> (real 'Newline'), not some Return- or
Enter-Key, because there is no mapping then. So simply hitting
exactly ":qa!<Ctrl-J>" (not the ") ends vim correctly.

In my test, if needing Ctr-Z too, I could run 'jobs -l' to show
the stopped 'job' (therein vim), and simply kill vim by pid number.

Dependig on how the shell created the pipe, the shell is still
the parent of that vim, then it's 'parent process' would be the
process id of the shell i.e. The numbber in '$$'. If your shell
has only the ONE vim as child, you might be able to write a script
to kill such a vim automagically. (e.g. search by 'pstree -p $$' or
simply by piping "jobs -l | vim_kill_script", then finding the
children of the shell, check for 'vim's pid and kill it.

Stucki

--
Christoph von Stuckrad * * | also XMPP = |Mail <stu...@mi.fu-berlin.de> \
Freie Universitaet Berlin |/_*| 'jabber' via|Tel(Mo.,Mi.):+49 30 838-75 459|
IT Mathematik & Informatik|\ *|stucki@jabber| (Di,Do,Fr):+49 30 77 39 6600|
Takustr. 9 / 14195 Berlin * * |.fu-berlin.de|Fax(home): +49 30 77 39 6601/

Reply all
Reply to author
Forward
0 new messages