Creative (and Crazy) Ways to Force‑Exit Vim
This article collects a variety of unconventional commands and tricks—from killing the Vim process to using Docker, timeout aliases, and even a playful Bash one‑liner—to force Vim to quit, while warning readers about the risks of such approaches.
Background
Luke Stephens created the GitHub repository how-to-exit-vim , which aggregates a variety of ways to force Vim to quit. The project quickly attracted over 2,400 stars and sparked discussion on Hacker News.
Process‑based termination methods
Kill the Vim process using ps to locate the PID:
:!ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9Kill Vim without ps by scanning /proc for the command line "vim":
:!kill -9 $(find /proc -name "cmdline" 2>/dev/null | while read procfile; do if grep -Pa '^vim\0' "$procfile" &>/dev/null; then echo $procfile; fi; done | awk -F'/' '{print $3}' | sort -u)Use the status file of each process to find Vim and kill it:
:!find /proc -name status | while read file; do echo "$file: "; cat $file | grep vim; done | grep -B1 vim | grep -v Name | while read line; do sed 's/^\/proc\///g' | sed 's/\/.*//g'; done | xargs kill -9Extract Vim’s parent PID directly from /proc/$$/status (shorter, no ps ):
:!grep -P "PPid:\t(\d+)" /proc/$$/status | cut -f2 | xargs kill -9Python one‑liner that obtains Vim’s PID via pidof and sends SIGTERM :
:py3 import os,signal;from subprocess import check_output;os.kill(int(check_output(["pidof","vim"]).decode('utf-8')),signal.SIGTERM)Obfuscated “shortest” method that builds a base64‑encoded command string and executes it:
:!x=$(echo c); x=$x$(echo G); x=$x$(echo t); x=$x$(echo p); x=$x$(echo b); x=$x$(echo G); x=$x$(echo w); x=$x$(echo g); x=$x$(echo L); x=$x$(echo V); x=$x$(echo N); x=$x$(echo U); x=$x$(echo T); x=$x$(echo 1); x=$x$(echo A); x=$x$(echo g); x=$x$(echo d); x=$x$(echo m); x=$x$(echo l); x=$x$(echo t); x=$x$(echo C); x=$x$(echo g); x=$x$(echo =); x=$x$(echo =); $(echo $x | base64 --decode)Higher‑level approaches
If Vim runs inside a Docker container, stop the container instead of killing the process directly:
docker run --rm -it --name my-vim -v `pwd`:/root thinkca/vim docker stop my-vimSet a timeout so Vim automatically exits after a given period (e.g., 10 minutes): timeout 600 vim Or create an alias that wraps Vim with the timeout command:
alias vim='timeout 600 vim'Safety note
Some of the one‑liners are intentionally destructive (e.g., pulling the power plug or executing obscure Bash code). Running them on a production machine can cause data loss or system instability; they are provided for illustration only.
References
GitHub repository: https://github.com/hakluke/how-to-exit-vim
Hacker News discussion: https://news.ycombinator.com/item?id=21988968
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
