1

Sometimes when a background process in Vim runs (in my case, compiling a poorly written LaTeX document) the background process stops which makes Vim unresponsive.

Terminating the process from terminal solves the problem but is cumbersome to execute. Ctrl c does not seem to work.

How should the background process be aborted?

Preferably, the process should be terminated but a solution that just unfreezes Vim is fine.

My current command is: :silent exec "!make"<CR>

A solution is to add a make vim in the makefile that ignores the errors but it would be nice to be able to force quit the process.

3
  • Do you need a synchronous solution (Vim waiting the compiler) or could you consider an asynchronous solution (Vim not waiting, the compiler working on the background). Commented Mar 3, 2023 at 15:57
  • 1
    Try C-\, which is a bit more forceful than C-c
    – D. Ben Knoble
    Commented Mar 3, 2023 at 21:41
  • Thank you @D.BenKnoble, that worked perfectly and also terminated the background process! If you write it as an answer I will accept it.
    – Hunaphu
    Commented Mar 4, 2023 at 17:43

2 Answers 2

2

Ctrl-\ (SIGQUIT) works in most unix terminals I’ve used and is more forceful than Ctrl-c (SIGINT). Try it when a program is misbehaving (but be careful hammering it in a nested context, where you might accidentally stop the inner and outer programs “unkindly”).

3
  • @Ben is it a Vim shortcut or only a terminal shortcut? Do we have to first switch to the terminal with Ctrl-Z Commented Mar 5, 2023 at 10:27
  • 2
    It's a terminal-level key, same as C-c, since it sends signals directly to the active process.
    – D. Ben Knoble
    Commented Mar 5, 2023 at 15:01
  • For me, it also works in gVim.
    – Hunaphu
    Commented Mar 6, 2023 at 1:58
1

My recommendation would be to use the asyncrun plugin.

If you were used to run :!mycompiler.sh, it let you run your compiler with a command like:

:AsyncRun mycompiler.sh

The output is sent to the QuickList and parsed using the errorformat.

You can stop the compiler using the command:

:AsyncStop
4
  • Thank you, I would prefer async but also I don't want any unnecessary dependencies, if the answer is that it is impossible to abort, then that's fine.
    – Hunaphu
    Commented Mar 3, 2023 at 18:23
  • 1
    Is the plugin an unnecessary dependencies? I'm not aware of standard asynchronous functionality and I believe it doesn't exist :-) Commented Mar 3, 2023 at 18:26
  • I see your point but always try to avoid all plugins.
    – Hunaphu
    Commented Mar 3, 2023 at 18:30
  • 1
    I understand. I have no solution to propose :-/ Commented Mar 3, 2023 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.