0

By mistake I ran a funny command today that looks like vi filename | vi - . It made my terminal stuck even Ctrl-C was of no use. I had to close the terminal only. I tried it a couple of times and tried on my friend machine too. Just wondering why Ctrl-C was also not able to help.

3 Answers 3

3

vi is reading from stdin.

When you edit in vi Ctrl+c does not work either.

To quit vi use :q or :q! will work like in a normal vi session.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I sometimes manage to call vim file | foo and this seems to also hang the terminal.
1

Using the POSIX function signal() a C program can choose what to do if there is a keyboard interrupt.

Here is an example (copied from this site):

#include <stdio.h> #include <stdlib.h> #include <signal.h> FILE *temp_file; void leave(int sig); main() { (void) signal(SIGINT, leave); temp_file = fopen("tmp", "w"); for(;;) { /* * Do things.... */ printf("Ready...\n"); (void)getchar(); } /* cant get here ... */ exit(EXIT_SUCCESS); } /* * on receipt of SIGINT, close tmp file */ void leave(int sig) { fprintf(temp_file,"\nInterrupted..\n"); fclose(temp_file); exit(sig); } 

But as you can see, vi doesn't use the keyboard interrupt to exit. It doesn't matter whether you are using it in a pipe or not.

Comments

0

Vi intercepts ctrl-c (it is almost equivalent to esc) so ctrl-c would not work to quit the application in that setting.

I could escape from that trap by using ctrl-z and then using kill %

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.