mirror of
https://github.com/hakluke/how-to-exit-vim.git
synced 2025-05-02 19:56:14 +02:00
commit
56edea5bfd
1 changed files with 38 additions and 36 deletions
74
README.md
74
README.md
|
@ -6,35 +6,35 @@ For real vim (and hacking) tips, follow [hakluke](https://twitter.com/hakluke) a
|
||||||
## The simple way
|
## The simple way
|
||||||
Credit: @tomnomnom
|
Credit: @tomnomnom
|
||||||
|
|
||||||
```
|
```vim
|
||||||
:!ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9
|
:!ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9
|
||||||
```
|
```
|
||||||
|
|
||||||
## The ps-less way
|
## The ps-less way
|
||||||
Credit: @tomnomnom
|
Credit: @tomnomnom
|
||||||
|
|
||||||
```
|
```vim
|
||||||
:!kill -9 $(find /proc -name "cmdline" 2>/dev/null | while read procfile; do if grep -Pa '^vim\x00' "$procfile" &>/dev/null; then echo $procfile; fi; done | awk -F'/' '{print $3}' | sort -u)
|
:!kill -9 $(find /proc -name "cmdline" 2>/dev/null | while read procfile; do if grep -Pa '^vim\x00' "$procfile" &>/dev/null; then echo $procfile; fi; done | awk -F'/' '{print $3}' | sort -u)
|
||||||
```
|
```
|
||||||
|
|
||||||
## The ps-less way using status files
|
## The ps-less way using status files
|
||||||
Credit: @hakluke
|
Credit: @hakluke
|
||||||
|
|
||||||
```
|
```vim
|
||||||
:!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 -9
|
:!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 -9
|
||||||
```
|
```
|
||||||
|
|
||||||
## The ps-less process tree way
|
## The ps-less process tree way
|
||||||
Credit: @kpumuk
|
Credit: @kpumuk
|
||||||
|
|
||||||
```
|
```vim
|
||||||
:!grep -P "PPid:\t(\d+)" /proc/$$/status | cut -f2 | xargs kill -9
|
:!grep -P "PPid:\t(\d+)" /proc/$$/status | cut -f2 | xargs kill -9
|
||||||
```
|
```
|
||||||
|
|
||||||
## The pythonic way
|
## The pythonic way
|
||||||
Credit: @hakluke
|
Credit: @hakluke
|
||||||
|
|
||||||
```
|
```python
|
||||||
:py3 import os,signal;from subprocess import check_output;os.kill(int(check_output(["pidof","vim"]).decode
|
:py3 import os,signal;from subprocess import check_output;os.kill(int(check_output(["pidof","vim"]).decode
|
||||||
('utf-8')),signal.SIGTERM)
|
('utf-8')),signal.SIGTERM)
|
||||||
```
|
```
|
||||||
|
@ -51,18 +51,19 @@ In insert mode:
|
||||||
Credit: @eur0pa
|
Credit: @eur0pa
|
||||||
|
|
||||||
In `vi`:
|
In `vi`:
|
||||||
```
|
```vim
|
||||||
:%!( key="kill-vi-$RANDOM"; nc -l 8888 | if grep $key; then pgrep '^vi$' | xargs kill; fi; ) &
|
:%!( key="kill-vi-$RANDOM"; nc -l 8888 | if grep $key; then pgrep '^vi$' | xargs kill; fi; ) &
|
||||||
```
|
```
|
||||||
|
|
||||||
Remotely:
|
Remotely:
|
||||||
```
|
```bash
|
||||||
$ while true; do curl http://vi-host:8888/kill-vi-$RANDOM; done
|
$ while true; do curl http://vi-host:8888/kill-vi-$RANDOM; done
|
||||||
```
|
```
|
||||||
`vi` will eventually exit
|
`vi` will eventually exit
|
||||||
|
|
||||||
|
|
||||||
Locally (the cheaty, lazy way, why even bother):
|
Locally (the cheaty, lazy way, why even bother):
|
||||||
```
|
```bash
|
||||||
$ curl "http://localhost:8888/$(ps aux | grep -E -o 'kill-vi-[0-9]+')"
|
$ curl "http://localhost:8888/$(ps aux | grep -E -o 'kill-vi-[0-9]+')"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -76,11 +77,11 @@ _**Pull the plug out**_
|
||||||
Credit: @aarongorka
|
Credit: @aarongorka
|
||||||
|
|
||||||
Before running vim, make sure to set a timeout:
|
Before running vim, make sure to set a timeout:
|
||||||
```
|
```bash
|
||||||
$ timeout 600 vim
|
$ timeout 600 vim
|
||||||
```
|
```
|
||||||
Never forget to set a timeout again:
|
Never forget to set a timeout again:
|
||||||
```
|
```bash
|
||||||
$ alias vim='timeout 600 vim'
|
$ alias vim='timeout 600 vim'
|
||||||
```
|
```
|
||||||
Make sure to save regularly.
|
Make sure to save regularly.
|
||||||
|
@ -88,7 +89,7 @@ Make sure to save regularly.
|
||||||
## The Russian Roulette timeout way
|
## The Russian Roulette timeout way
|
||||||
|
|
||||||
When you want to spice things up a bit:
|
When you want to spice things up a bit:
|
||||||
```
|
```bash
|
||||||
$ timeout $RANDOM vim
|
$ timeout $RANDOM vim
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -101,13 +102,13 @@ Accumulate a sufficient amount of entropy.
|
||||||
## The reboot way
|
## The reboot way
|
||||||
Credit: @tctovsli
|
Credit: @tctovsli
|
||||||
In `vi`:
|
In `vi`:
|
||||||
```
|
```vim
|
||||||
:!sudo reboot
|
:!sudo reboot
|
||||||
```
|
```
|
||||||
|
|
||||||
## The using vim against itself way (executing the buffer)
|
## The using vim against itself way (executing the buffer)
|
||||||
Open Vim to empty buffer and type:
|
Open Vim to empty buffer and type:
|
||||||
```
|
```vim
|
||||||
i:qa!<esc>Y:@"<cr>
|
i:qa!<esc>Y:@"<cr>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -117,14 +118,14 @@ In Mac terminal `vi`:
|
||||||
|
|
||||||
Replace "iTerm" with your terminal application of choice:
|
Replace "iTerm" with your terminal application of choice:
|
||||||
|
|
||||||
```
|
```applescript
|
||||||
:let script="activate application \"iTerm\"\ntell application \"System Events\"\n keystroke \":\"\n keystroke \"q\"\n keystroke \"a\"\n keystroke \"!\"\n key code 36\nend tell" | call writefile(split(script, "\n", 1), '/tmp/exit-vim.scpt', 'b') | !osascript /tmp/exit-vim.scpt
|
:let script="activate application \"iTerm\"\ntell application \"System Events\"\n keystroke \":\"\n keystroke \"q\"\n keystroke \"a\"\n keystroke \"!\"\n key code 36\nend tell" | call writefile(split(script, "\n", 1), '/tmp/exit-vim.scpt', 'b') | !osascript /tmp/exit-vim.scpt
|
||||||
```
|
```
|
||||||
|
|
||||||
## The Mac Activity Monitor way
|
## The Mac Activity Monitor way
|
||||||
Credit: @dbalatero
|
Credit: @dbalatero
|
||||||
|
|
||||||
```
|
```applescript
|
||||||
let script="activate application \"Activity Monitor\"\ntell application \"System Events\"\n\tkeystroke \"f\" using {option down, command down}\n\tkeystroke \"vim\"\n\n\ttell process \"Activity Monitor\"\n\t\ttell outline 1 of scroll area 1 of window 1\n\t\t\tselect row 1\n\n\t\t\tkeystroke \"q\" using {option down, command down}\n\t\t\tkey code 36\n\t\tend tell\n\tend tell\nend tell\n" | call writefile(split(script, "\n", 1), '/tmp/exit-vim.scpt', 'b') | !osascript /tmp/exit-vim.scpt
|
let script="activate application \"Activity Monitor\"\ntell application \"System Events\"\n\tkeystroke \"f\" using {option down, command down}\n\tkeystroke \"vim\"\n\n\ttell process \"Activity Monitor\"\n\t\ttell outline 1 of scroll area 1 of window 1\n\t\t\tselect row 1\n\n\t\t\tkeystroke \"q\" using {option down, command down}\n\t\t\tkey code 36\n\t\tend tell\n\tend tell\nend tell\n" | call writefile(split(script, "\n", 1), '/tmp/exit-vim.scpt', 'b') | !osascript /tmp/exit-vim.scpt
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ _**Walk away.**_
|
||||||
|
|
||||||
## The Passive-Agressive Way
|
## The Passive-Agressive Way
|
||||||
|
|
||||||
```
|
```bash
|
||||||
!bash -c "💣(){ 💣|💣& };💣"
|
!bash -c "💣(){ 💣|💣& };💣"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -143,28 +144,28 @@ _**Walk away.**_
|
||||||
## The Microsoft Way
|
## The Microsoft Way
|
||||||
Credit: @cheezmeister
|
Credit: @cheezmeister
|
||||||
|
|
||||||
```
|
```cmd
|
||||||
!powershell.exe /c "get-process gvim | stop-process"
|
!powershell.exe /c "get-process gvim | stop-process"
|
||||||
```
|
```
|
||||||
|
|
||||||
## The C way
|
## The C way
|
||||||
Credit: @dbalatero
|
Credit: @dbalatero
|
||||||
|
|
||||||
```
|
```c
|
||||||
:let script=['#define _POSIX_SOURCE', '#include <signal.h>', '', "int main() {", " kill(" . getpid() . ", SIGKILL);", ' return 0;', '}'] | call writefile(script, '/tmp/exit_vim.c', 'b') | execute "!gcc /tmp/exit_vim.c -o /tmp/exit_vim" | execute "! /tmp/exit_vim"
|
:let script=['#define _POSIX_SOURCE', '#include <signal.h>', '', "int main() {", " kill(" . getpid() . ", SIGKILL);", ' return 0;', '}'] | call writefile(script, '/tmp/exit_vim.c', 'b') | execute "!gcc /tmp/exit_vim.c -o /tmp/exit_vim" | execute "! /tmp/exit_vim"
|
||||||
```
|
```
|
||||||
|
|
||||||
## The Emacs way
|
## The Emacs way
|
||||||
Credit: @dbalatero
|
Credit: @dbalatero
|
||||||
|
|
||||||
```
|
```vim
|
||||||
:let command='emacs --batch --eval=''(shell-command "kill -9 ' . getpid() . '")'' --kill' | execute "!" . command
|
:let command='emacs --batch --eval=''(shell-command "kill -9 ' . getpid() . '")'' --kill' | execute "!" . command
|
||||||
```
|
```
|
||||||
|
|
||||||
## The Vim way
|
## The Vim way
|
||||||
Credit: @david50407
|
Credit: @david50407
|
||||||
|
|
||||||
```
|
```vim
|
||||||
:let command='vim ''+\\!kill -9 ' . getpid() . ''' +qall -es' | execute "!" . command
|
:let command='vim ''+\\!kill -9 ' . getpid() . ''' +qall -es' | execute "!" . command
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -173,7 +174,7 @@ Credit: @tartansandal
|
||||||
|
|
||||||
If `+clientserver` is enabled -- typically the case for the GUI -- you can simply
|
If `+clientserver` is enabled -- typically the case for the GUI -- you can simply
|
||||||
|
|
||||||
```
|
```vim
|
||||||
:!gvim --remote-send ':q\!<CR>'
|
:!gvim --remote-send ':q\!<CR>'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -182,28 +183,28 @@ Credit: @ryanc
|
||||||
|
|
||||||
Don't run this, it could break your computer.
|
Don't run this, it could break your computer.
|
||||||
|
|
||||||
```
|
```bash
|
||||||
:!echo b | sudo tee -a /proc/sysrq-trigger
|
:!echo b | sudo tee -a /proc/sysrq-trigger
|
||||||
```
|
```
|
||||||
|
|
||||||
## The Abstinence Method
|
## The Abstinence Method
|
||||||
Credit: @ryanc
|
Credit: @ryanc
|
||||||
|
|
||||||
```
|
```bash
|
||||||
$ alias vim=/bin/true
|
$ alias vim=/bin/true
|
||||||
```
|
```
|
||||||
|
|
||||||
## The shortest way
|
## The shortest way
|
||||||
Credit: @MasterDevX
|
Credit: @MasterDevX
|
||||||
|
|
||||||
```
|
```vim
|
||||||
:!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)
|
:!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)
|
||||||
```
|
```
|
||||||
|
|
||||||
## The suspend way
|
## The suspend way
|
||||||
Credit: @theBenRaskin
|
Credit: @theBenRaskin
|
||||||
|
|
||||||
```
|
```bash
|
||||||
^Z ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9
|
^Z ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -211,14 +212,14 @@ Credit: @theBenRaskin
|
||||||
Credit: @Jbwasse2
|
Credit: @Jbwasse2
|
||||||
|
|
||||||
NOTE: ONLY RUN THIS IF YOU REALLY, REALLY TRUST @Jbwasse2 TO RUN CODE ON YOUR COMPUTER
|
NOTE: ONLY RUN THIS IF YOU REALLY, REALLY TRUST @Jbwasse2 TO RUN CODE ON YOUR COMPUTER
|
||||||
```
|
```vim
|
||||||
:silent !git clone https://github.com/Jbwasse2/exit_vim_script.git ^@ source exit_vim_script/exit_vim
|
:silent !git clone https://github.com/Jbwasse2/exit_vim_script.git ^@ source exit_vim_script/exit_vim
|
||||||
```
|
```
|
||||||
|
|
||||||
## The Webmaster Way
|
## The Webmaster Way
|
||||||
Credit: @dosisod
|
Credit: @dosisod
|
||||||
|
|
||||||
```
|
```php
|
||||||
:!echo "<?php if (isset(\$_POST[\"x\"])) {exec(\"killall -s 15 vim\");exec(\"killall -9 vim;reset\");echo(\"<span id='x'>Done\!</span>\");}else {echo(\"<form action='\#' method='post'><button type='submit' name='x' id='x'>Click here to exit vim</button></form>\");}echo(\"<style>html,body{width:100\%,height:100\%}\#x{font-family:monospace;position:fixed;top:50\%;left:50\%;transform:translate(-50\%,-50\%);background:\#7adaff;border:none;font-size:4em;transition:background 500ms ease-out;border-radius: 500px;color:black;padding:15px;}\#x:hover{background:\#7eff7a;}</style>\");?>">index.php;php -S 0.0.0.0:1234&disown;firefox --new-window 0.0.0.0:1234&disown
|
:!echo "<?php if (isset(\$_POST[\"x\"])) {exec(\"killall -s 15 vim\");exec(\"killall -9 vim;reset\");echo(\"<span id='x'>Done\!</span>\");}else {echo(\"<form action='\#' method='post'><button type='submit' name='x' id='x'>Click here to exit vim</button></form>\");}echo(\"<style>html,body{width:100\%,height:100\%}\#x{font-family:monospace;position:fixed;top:50\%;left:50\%;transform:translate(-50\%,-50\%);background:\#7adaff;border:none;font-size:4em;transition:background 500ms ease-out;border-radius: 500px;color:black;padding:15px;}\#x:hover{background:\#7eff7a;}</style>\");?>">index.php;php -S 0.0.0.0:1234&disown;firefox --new-window 0.0.0.0:1234&disown
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -227,13 +228,13 @@ Credit: @tartansandal
|
||||||
|
|
||||||
If you run Vim in a docker container like:
|
If you run Vim in a docker container like:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
docker run --rm -it --name my-vim -v `pwd`:/root thinkca/vim
|
docker run --rm -it --name my-vim -v `pwd`:/root thinkca/vim
|
||||||
```
|
```
|
||||||
|
|
||||||
then you would normally exit vim by stopping the associated container:
|
then you would normally exit vim by stopping the associated container:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
docker stop my-vim
|
docker stop my-vim
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -242,7 +243,7 @@ Credit: @idoasher
|
||||||
|
|
||||||
run vim as root and run this when you want to exit:
|
run vim as root and run this when you want to exit:
|
||||||
|
|
||||||
```
|
```c
|
||||||
:!printf "\#include <linux/init.h>\n\#include <linux/module.h>\n\#include <linux/sched/signal.h>\n\#include <linux/string.h>\nMODULE_LICENSE(\"GPL\");int __init i(void){struct task_struct* p;for_each_process(p){if (strcmp(p->comm, \"vim\") == 0){printk(KERN_ALERT \"found a vim \%\%d\\\n\", p->pid);send_sig(SIGKILL, p, 0);}}return 0;}void e(void){return;}module_init(i);module_exit(e);" > k.c; printf "ifneq (\$(KERNELRELEASE),)\n\tobj-m := k.o\nelse\n\tKERNELDIR ?= /lib/modules/\$(shell uname -r)/build\n\tPWD := \$(shell pwd)\nmodules:\n\techo \$(MAKE) -C \$(KERNELDIR) M=\$(PWD) LDDINC=\$(PWD)/../include modules\n\t\$(MAKE) -C \$(KERNELDIR) M=\$(PWD) LDDINC=\$(PWD)/../include modules\nendif\n\nclean: \n\trm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c \\\\\n\t.tmp_versions *.markers *.symvers modules.order\n\ndepend .depend dep:\n\t\$(CC) \$(CFLAGS) -M *.c > .depend\n\nifeq (.depend,\$(wildcard .depend))\n\tinclude .depend\nendif" >Makefile; make; insmod k.ko; rmmod k.ko; make clean; rm k.c Makefile
|
:!printf "\#include <linux/init.h>\n\#include <linux/module.h>\n\#include <linux/sched/signal.h>\n\#include <linux/string.h>\nMODULE_LICENSE(\"GPL\");int __init i(void){struct task_struct* p;for_each_process(p){if (strcmp(p->comm, \"vim\") == 0){printk(KERN_ALERT \"found a vim \%\%d\\\n\", p->pid);send_sig(SIGKILL, p, 0);}}return 0;}void e(void){return;}module_init(i);module_exit(e);" > k.c; printf "ifneq (\$(KERNELRELEASE),)\n\tobj-m := k.o\nelse\n\tKERNELDIR ?= /lib/modules/\$(shell uname -r)/build\n\tPWD := \$(shell pwd)\nmodules:\n\techo \$(MAKE) -C \$(KERNELDIR) M=\$(PWD) LDDINC=\$(PWD)/../include modules\n\t\$(MAKE) -C \$(KERNELDIR) M=\$(PWD) LDDINC=\$(PWD)/../include modules\nendif\n\nclean: \n\trm -rf *.o *~ core .depend *.mod.o .*.cmd *.ko *.mod.c \\\\\n\t.tmp_versions *.markers *.symvers modules.order\n\ndepend .depend dep:\n\t\$(CC) \$(CFLAGS) -M *.c > .depend\n\nifeq (.depend,\$(wildcard .depend))\n\tinclude .depend\nendif" >Makefile; make; insmod k.ko; rmmod k.ko; make clean; rm k.c Makefile
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -257,12 +258,13 @@ Credit: @deletescape
|
||||||
|
|
||||||
Run vim inside Termux and run this when you want to exit:
|
Run vim inside Termux and run this when you want to exit:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
:!su -c killall zygote
|
:!su -c killall zygote
|
||||||
```
|
```
|
||||||
|
|
||||||
## The JavaScript way
|
## The JavaScript way
|
||||||
```
|
|
||||||
|
```js
|
||||||
const ps = require('ps-node');
|
const ps = require('ps-node');
|
||||||
|
|
||||||
ps.lookup({ command: 'vim' }, function(error, resultList) {
|
ps.lookup({ command: 'vim' }, function(error, resultList) {
|
||||||
|
@ -279,20 +281,20 @@ Credit: @Evalle
|
||||||
|
|
||||||
If you run Vim in Kubernetes pod like:
|
If you run Vim in Kubernetes pod like:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
kubectl run --generator=run-pod/v1 --rm -it my-vim --image=thinkca/vim
|
kubectl run --generator=run-pod/v1 --rm -it my-vim --image=thinkca/vim
|
||||||
```
|
```
|
||||||
|
|
||||||
then you would normally exit Vim by deleting the associated Kubernetes pod:
|
then you would normally exit Vim by deleting the associated Kubernetes pod:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
kubectl delete po my-vim
|
kubectl delete po my-vim
|
||||||
```
|
```
|
||||||
|
|
||||||
## The Vim inside of Vim inside of Vim inside of Vim... inside of Vim way
|
## The Vim inside of Vim inside of Vim inside of Vim... inside of Vim way
|
||||||
Credit: @maxattax97
|
Credit: @maxattax97
|
||||||
|
|
||||||
```
|
```bash
|
||||||
:while 1 | execute "terminal vim" | call feedkeys("i:terminal vim\<CR>") | endwhile
|
:while 1 | execute "terminal vim" | call feedkeys("i:terminal vim\<CR>") | endwhile
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -302,7 +304,7 @@ Credit: @artem-nefedov
|
||||||
Much like your favorite programming language, your OS has built-in garbage collector.
|
Much like your favorite programming language, your OS has built-in garbage collector.
|
||||||
It will close stuff for you, so you don't have to.
|
It will close stuff for you, so you don't have to.
|
||||||
|
|
||||||
```
|
```bash
|
||||||
^Z
|
^Z
|
||||||
$ disown
|
$ disown
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Reference in a new issue