Looking at the source code, there doesn't seem to be a way to prevent Vim from suspending if the :suspend
command is executed. See Ingo Karkat's answer for a discussion of how to prevent the command from being executed.
Unless, that is, one changes the Vim binary. Write the following code to a file override_kill.c
:
#define _GNU_SOURCE
#include <dlfcn.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int kill(pid_t pid, int sig) {
int (*original_kill)(pid_t, int) = dlsym(RTLD_NEXT, "kill");
if (pid == 0 && sig == SIGSTOP) {
/*Don't suspend, initiate resuming*/
original_kill(0, SIGCONT);
return 0;
} else {
return original_kill(pid, sig);
}
}
Compile with
gcc -O -Wall -fPIC -shared -o override_kill.so override_kill.c -dl
Instead of directly running Vim from a terminal emulator, run
env LD_PRELOAD=/path/to/override_kill.so vim
Vim will go through the motions of suspending but immediately resume execution. (Only on a terminal: the GUI version will iconify as usual.)
Only tested under Linux; this probably works under most Unix-like operating system, except that they may require different compiler options. OSX should work with DYLD_PRELOAD
instead of LD_PRELOAD
.
This technique cannot be generalize to overriding arbitrary commands: only library calls can be overridden this way, not calls to functions that are internal to the Vim binary. (That's why the modified program still goes through the motions and only the actual suspension is overridden.)