I have a quick question about programming using Vim. I sometimes make a silly mistake in my program.

For example, the Python code below has an infinite loop (say foo.py . . . be careful when executing it!)

x = 1
while x == 1:
x = 1

You won't see any result, but find a fan inside your computer is becoming louder, and you need to stop executing this Python program. On a Unix shell, you can do it by pressing Ctrl-z. Or, on Emacs shell-mode, just pressing Ctrl-c Ctrl-z.

I know how to switch to shell-mode in Vim: :sh (then type python foo.py) or :!python foo.py. But I don't know how to stop a job on a shell from Vim without killing Vim itself. Does anyone know this?

3 Answers
3

Why can't you use <C-C>? By default, it sends an INTerrupt signal unless program is able to catch <C-C>. Vim handles <C-C> like any other <C-...> key, but python does not do this by default.

By the way, <C-Z> in unix shells suspends program while in the case mentioned above you need to kill it which is done using <C-C>. Suspend=pause executing (though most programs are not able to/do not need to handle SIGTSTP/SIGCONT properly).

You meant, from another terminal emulator? When a certain job is running on a shell on Vim, it seems impossible to put any Unix command except for Ctrl-z which kills Vim as well.
–
CulipNov 12 '10 at 16:29

For example, when you write the code above on Vim and switch to a shell by pressing :sh, and execute it like python foo.py, and you want to suspend the python program and return to the shell or Vim, without killing Vim itself (i.e. not Ctrl-D.)
–
CulipNov 12 '10 at 17:25