├── assets ├── jeffrey.jpeg └── first-contact-way.png └── README.md /assets/jeffrey.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hakluke/how-to-exit-vim/HEAD/assets/jeffrey.jpeg -------------------------------------------------------------------------------- /assets/first-contact-way.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hakluke/how-to-exit-vim/HEAD/assets/first-contact-way.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to exit vim 2 | Below are some simple methods for exiting vim. 3 | 4 | For real vim (and hacking) tips, follow [hakluke](https://twitter.com/hakluke) and [tomnomnom](https://twitter.com/tomnomnom) on twitter. 5 | 6 | ## The simple way 7 | Credit: @tomnomnom 8 | 9 | ```vim 10 | :!ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9 11 | ``` 12 | ### Video tutorial: 13 | [![tomnomnom](http://img.youtube.com/vi/xteTjU8GNMc/0.jpg)](http://www.youtube.com/watch?v=xteTjU8GNMc "tomnomnom") 14 | 15 | ## The ps-less way 16 | Credit: @tomnomnom 17 | 18 | ```vim 19 | :!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) 20 | ``` 21 | 22 | 23 | ## The ps-less way using status files 24 | Credit: @hakluke 25 | 26 | ```vim 27 | :!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 28 | ``` 29 | 30 | ## The ps-less process tree way 31 | Credit: @kpumuk 32 | 33 | ```vim 34 | :!grep -P "PPid:\t(\d+)" /proc/$$/status | cut -f2 | xargs kill -9 35 | ``` 36 | 37 | ## The first contact way 38 | Credit: @caseyjohnellis 39 | ![Jeffrey Way](assets/first-contact-way.png) 40 | 41 | ## The lazy pythonic using shell way 42 | Credit: @PozziSan 43 | 44 | ```bash 45 | python -c "from os import system; system('killall -9 vim')" 46 | ```` 47 | 48 | ## The pythonic way 49 | Credit: @hakluke 50 | 51 | ```python 52 | :py3 import os,signal;from subprocess import check_output;os.kill(int(check_output(["pidof","vim"]).decode 53 | ('utf-8')),signal.SIGTERM) 54 | ``` 55 | 56 | ## The pure perl way 57 | ```perl 58 | :!perl -e 'while(){open($f, "$_/cmdline"); kill 9, substr($_,6) if <$f> =~ m|^vim\x00| }' 59 | ``` 60 | 61 | ## The Rustacean's way 62 | Credit: @wodny 63 | 64 | 1. Reimplement vim in Rust. 65 | 2. Call the project `rim`. 66 | 3. Run `rim`. 67 | 4. Exit `rim` using a borrowed command, ie. `:q!`. 68 | 69 | ## The lazy rubist using shell way 70 | Credit: @rynaro 71 | 72 | ```bash 73 | $ ruby -e 'system("killall -9 vim")' 74 | ``` 75 | 76 | ## The rubist way 77 | Credit: @rynaro 78 | 79 | ```bash 80 | $ ruby -e 'pid = `pidof vim`; Process.kill(9, pid.to_i)' 81 | ``` 82 | 83 | ## The Colon-less way 84 | Credit: @w181496 85 | 86 | In insert mode: 87 | ```vim 88 | =system("ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9") 89 | ``` 90 | 91 | ## The remote way 92 | Credit: @eur0pa 93 | 94 | In `vi`: 95 | ```vim 96 | :%!( key="kill-vi-$RANDOM"; nc -l 8888 | if grep $key; then pgrep '^vi$' | xargs kill; fi; ) & 97 | ``` 98 | 99 | Remotely: 100 | ```bash 101 | $ while true; do curl http://vi-host:8888/kill-vi-$RANDOM; done 102 | ``` 103 | `vi` will eventually exit 104 | 105 | 106 | Locally (the cheaty, lazy way, why even bother): 107 | ```bash 108 | $ curl "http://localhost:8888/$(ps aux | grep -E -o 'kill-vi-[0-9]+')" 109 | ``` 110 | 111 | ## The hardware way 112 | Credit: @Jorengarenar 113 | 114 | _**Pull the plug out**_ 115 | 116 | 117 | ## The hardware expert way 118 | Use VIMKiller! The most practical physical solution to all your VIM troubles. It only costs 500,000 USD! 119 | 120 | [VIMKiller git](https://github.com/caseykneale/VIMKiller) 121 | 122 | ## The timeout way 123 | 124 | Credit: @aarongorka 125 | 126 | Before running vim, make sure to set a timeout: 127 | ```bash 128 | $ timeout 600 vim 129 | ``` 130 | Never forget to set a timeout again: 131 | ```bash 132 | $ alias vim='timeout 600 vim' 133 | ``` 134 | Make sure to save regularly. 135 | 136 | ## The Russian Roulette timeout way 137 | 138 | When you want to spice things up a bit: 139 | ```bash 140 | $ timeout $RANDOM vim 141 | ``` 142 | 143 | ## The Shoot First, Ask Questions Later way 144 | Credit: @aliva 145 | 146 | ```bash 147 | $ ps axuw | awk '{print $2}' | grep -v PID | shuf -n 1 | sudo kill -9 148 | ``` 149 | 150 | ## The "all against the odds" Russian Roulette way 151 | Credit: @cfrost 152 | 153 | When you want to spice things up a bit more: 154 | ```vim 155 | :!ps axuw | sort -R | head -1 | awk '{print $2}' | xargs kill -9 156 | ``` 157 | 158 | ## The physics way 159 | Credit: @eyemyth 160 | 161 | Accumulate a sufficient amount of entropy. 162 | 163 | 164 | ## The reboot way 165 | Credit: @tctovsli 166 | In `vi`: 167 | ```vim 168 | :!sudo reboot 169 | ``` 170 | 171 | ## The using vim against itself way (executing the buffer) 172 | Open Vim to empty buffer and type: 173 | ```vim 174 | i:qa!Y:@" 175 | ``` 176 | 177 | ## The AppleScript way 178 | Credit: @dbalatero 179 | In Mac terminal `vi`: 180 | 181 | Replace "iTerm" with your terminal application of choice: 182 | 183 | ```applescript 184 | :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 185 | ``` 186 | 187 | ## The Mac Activity Monitor way 188 | Credit: @dbalatero 189 | 190 | ```applescript 191 | 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 192 | ``` 193 | 194 | ## The MacBook Pro Touch Bar way 195 | Credit: @IA_Baby46 196 | 197 | Touch `quit vim` text in your touch bar 198 | 199 | ## The Mac Terminal way 200 | 201 | Press +q > Click `Terminate` 202 | 203 | 204 | ## The Passive Way 205 | 206 | _**Walk away.**_ 207 | 208 | ## The Passive-Aggressive Way 209 | 210 | ```bash 211 | !bash -c "💣(){ 💣|💣& };💣" 212 | ``` 213 | 214 | *...then walk away.* (n.b. That's a [fork bomb](https://en.wikipedia.org/wiki/Fork_bomb#Bash), please don't try at home.) 215 | 216 | ## The Microsoft Way 217 | Credit: @cheezmeister 218 | 219 | ```cmd 220 | !powershell.exe /c "get-process gvim | stop-process" 221 | ``` 222 | 223 | ## The C way 224 | Credit: @dbalatero 225 | 226 | ```c 227 | :let script=['#define _POSIX_SOURCE', '#include ', '', "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" 228 | ``` 229 | 230 | ## The Emacs way 231 | Credit: @dbalatero 232 | 233 | ```vim 234 | :let command='emacs --batch --eval=''(shell-command "kill -9 ' . getpid() . '")'' --kill' | execute "!" . command 235 | ``` 236 | 237 | ## The Vim way 238 | Credit: @david50407 239 | 240 | ```vim 241 | :let command='vim ''+\\!kill -9 ' . getpid() . ''' +qall -es' | execute "!" . command 242 | ``` 243 | 244 | ## The Client-Server way 245 | Credit: @tartansandal 246 | 247 | If `+clientserver` is enabled -- typically the case for the GUI -- you can simply 248 | 249 | ```vim 250 | :!gvim --remote-send ':q\!' 251 | ``` 252 | 253 | ## The Yolo Way 254 | Credit: @ryanc 255 | 256 | Don't run this, it could break your computer. 257 | 258 | ```bash 259 | :!echo b | sudo tee -a /proc/sysrq-trigger 260 | ``` 261 | 262 | ## The layered Method 263 | Credit: @mashuptwice 264 | ```vim 265 | :!python -c "import os ; os.system(\"ssh localhost kill -9 $(pgrep vim >tmpfile && grep -P '\d+' tmpfile | sed 's/\(.*\)/\1/g' | cat && rm tmpfile) \")" 266 | ``` 267 | Bonus: still stuck if multiple vim instances are running 268 | 269 | ## The epileptic Method 270 | Credit: @mashuptwice 271 | ```vim 272 | :!timeout 10 yes "Preparing to exit vim. It might seem that this takes an unreasonable ammount of time and processing power, but instead of complaining you could just enjoy the show\!" | lolcat ; pgrep vim | xargs kill -9 273 | ``` 274 | May the magnificent colors help you to forget the emotional damage caused by exiting vim! 275 | 276 | ## The Abstinence Method 277 | Credit: @ryanc 278 | 279 | ```bash 280 | $ alias vim=/bin/true 281 | ``` 282 | 283 | ## The Passive-Aggressive Abstinence Method 284 | Credit: @donkoch 285 | 286 | ```bash 287 | $ alias vim=/bin/false 288 | ``` 289 | 290 | ## The shortest way 291 | Credit: @MasterDevX 292 | 293 | ```vim 294 | :!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) 295 | ``` 296 | 297 | ## The suspend way 298 | Credit: @theBenRaskin 299 | 300 | ```bash 301 | ^Z ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9 302 | ``` 303 | 304 | ## The Minimal, Open-Source way 305 | Credit: @Jbwasse2 306 | 307 | NOTE: ONLY RUN THIS IF YOU REALLY, REALLY TRUST @Jbwasse2 TO RUN CODE ON YOUR COMPUTER 308 | ```vim 309 | :silent !git clone https://github.com/Jbwasse2/exit_vim_script.git ^@ source exit_vim_script/exit_vim 310 | ``` 311 | 312 | ## The Acceptance Way 313 | Credit: @praveenscience 314 | 315 | Just stay in Vim 😊 🤘🏻 316 | 317 | ## The Webmaster Way 318 | Credit: @dosisod 319 | 320 | ```php 321 | :!echo "Done\!\");}else {echo(\"
\");}echo(\"\");?>">index.php;php -S 0.0.0.0:1234&disown;firefox --new-window 0.0.0.0:1234&disown 322 | ``` 323 | 324 | ## The Docker way 325 | Credit: @tartansandal 326 | 327 | If you run Vim in a docker container like: 328 | 329 | ```bash 330 | docker run --name my-vim -v `pwd`:/root thinca/vim 331 | ``` 332 | 333 | then you would normally exit vim by stopping the associated container: 334 | 335 | ```bash 336 | docker stop my-vim 337 | ``` 338 | 339 | ## The Kernel way 340 | Credit: @idoasher 341 | 342 | run vim as root and run this when you want to exit: 343 | 344 | ```c 345 | :!printf "\#include \n\#include \n\#include \n\#include \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 346 | 347 | ``` 348 | 349 | ## The even more Extreme Kernel Way 350 | Credit: @penelopezone 351 | 352 | **Warning, this may break your entire computer** 353 | 354 | ```vim 355 | :!sudo dd if=/dev/urandom of=/dev/kmem 356 | ``` 357 | 358 | 359 | ## The Android way 360 | Credit: @deletescape 361 | 362 | Close the Termux app. 363 | 364 | ## The extreme Android way 365 | Credit: @deletescape 366 | 367 | Run vim inside Termux and run this when you want to exit: 368 | 369 | ```bash 370 | :!su -c killall zygote 371 | ``` 372 | 373 | ## The JavaScript way 374 | 375 | ```js 376 | const ps = require('ps-node'); 377 | 378 | ps.lookup({ command: 'vim' }, function(error, resultList) { 379 | resultList.forEach(function(process) { 380 | if (process) { 381 | ps.kill(process.pid); 382 | } 383 | }); 384 | }); 385 | ``` 386 | 387 | ## The Kubernetes way 388 | Credit: @Evalle 389 | 390 | If you run Vim in Kubernetes pod like: 391 | 392 | ```bash 393 | kubectl run --generator=run-pod/v1 my-vim --image=thinca/vim 394 | ``` 395 | 396 | then you would normally exit Vim by deleting the associated Kubernetes pod: 397 | 398 | ```bash 399 | kubectl delete po my-vim 400 | ``` 401 | 402 | ## The Vim inside of Vim inside of Vim inside of Vim... inside of Vim way 403 | Credit: @maxattax97 404 | 405 | ```bash 406 | :while 1 | execute "terminal vim" | call feedkeys("i:terminal vim\") | endwhile 407 | ``` 408 | 409 | ## Let "automatic garbage collector" do it for you 410 | Credit: @artem-nefedov 411 | 412 | Much like your favorite programming language, your OS has built-in garbage collector. 413 | It will close stuff for you, so you don't have to. 414 | 415 | ```bash 416 | ^Z 417 | $ disown 418 | ``` 419 | 420 | Now it's not your problem anymore. 421 | Process will close automatically upon next reboot/shutdown. 422 | 423 | ## The Product Manager way 424 | Credit: @mqchen 425 | 426 | 1. Create new Jira issue. 427 | 2. Set priority to A - Critical. 428 | 3. Assign to random team member. 429 | 430 | ## The Experienced Product Manager way 431 | Credit: @mqchen 432 | 433 | 1. Create new Jira issue. 434 | 2. Set priority to A - Critical, Epic link and Components. 435 | 3. Write Given-When-Then acceptance criteria. 436 | 4. Schedule estimation workshop meeting. 437 | 5. Conduct estimation meeting with Planning Poker cards. 438 | 6. Prioritize in next sprint. 439 | 7. Assign to random team member. 440 | 8. Conduct acceptance test. 441 | 9. Review burn down chart together with the team. 442 | 10. Schedule retrospective. 443 | 444 | ## The spiritual way 445 | Credit: @Janice-M 446 | 1. Take a cleansing bath 447 | 2. Weditate 448 | 3. Sage your house 449 | 4. Place crystals on your laptop 450 | 5. Burn your laptop and whole house down 451 | 6. Set your slack status to 'away' indefinitely 452 | 7. Move to the forest 453 | 454 | ## The tmux way 455 | Credit: @vcoutasso 456 | 457 | Inside a tmux session: 458 | 459 | ``` 460 | Ctrl+B :kill-session 461 | ``` 462 | alternativelycd 463 | 464 | ``` 465 | Ctrl+B x y 466 | ``` 467 | 468 | Note that ```Ctrl+B``` is the default prefix. For different prefixes, the command must be adjusted accordingly. 469 | 470 | ## The Mathematician's way 471 | 472 | Define yourself outside vim. 473 | 474 | ## The Intern way 475 | Credit: @johnoct 476 | 477 | 1. Don't even try to exit on your own 478 | 2. Ask Senior right away 479 | 480 | ## The Mandalorian way 481 | 482 | ```vim 483 | :let hash=sha256("$$$ this is the way $$$") | exe nr2char(hash[49:51]).hash[-3:-3]."!" 484 | ``` 485 | 486 | ## The debugger way 487 | Credit: @serjepatoff 488 | 489 | Linux 490 | ``` 491 | $ gdb `which vim` 492 | (gdb) r 493 | Ctrl-Z q y 494 | ``` 495 | 496 | Mac 497 | ``` 498 | $ lldb `which vim` 499 | (lldb) r 500 | Ctrl-C q 501 | ``` 502 | 503 | ## The libcall way 504 | Credit: @k-takata 505 | 506 | ### Windows 507 | ```vim 508 | :call libcallnr('kernel32.dll', 'ExitProcess', 0) 509 | 510 | ``` 511 | 512 | ## The Vagrant way 513 | Credit: @85danf 514 | 515 | To run vim: 516 | ```bash 517 | mkdir -p /tmp/vim 518 | cd /tmp/vim 519 | vagrant init --minimal hashicorp/bionic64 520 | vagrant ssh 521 | vim 522 | ``` 523 | To exit vim, open another shell, then: 524 | ```bash 525 | cd /tmp/vim 526 | vagrant halt 527 | ``` 528 | 529 | ## The consonant cluster way 530 | Credit: @wchargin 531 | 532 | To exit, saving all files, simply incant (in normal mode): 533 | 534 | ```vim 535 | qqqqqZZ@qq@q 536 | ``` 537 | 538 | ## The customer success way 539 | Credit: @85danf 540 | 541 | 1. Schedule emergency meeting with R&D about 'worrisome trends apparent in recent support tickets metrics' 542 | 2. Present ability to exit vim as probable root cause 543 | 3. Wait as developers argue and mansplain stuff 544 | 4. Schedule follow up meeting for next quarter 545 | 5. Not your problem anymore 546 | 547 | ## The Matrix way 548 | Credit: @85danf 549 | 550 | "There is no vim" 551 | 552 | ## The SEO Manager way 553 | Credit: @mikulabc 554 | 555 | ``` 556 | how to exit vim 557 | vim exit help 558 | vim exit guide 559 | exit him 560 | how exit vim 561 | ``` 562 | 563 | ## Linux 564 | ```vim 565 | :call libcallnr('libc.so.6', 'exit', 0) 566 | ``` 567 | 568 | ## The canonical way 569 | Credit: @ligurio 570 | 571 | ```vim 572 | :!q 573 | ``` 574 | 575 | ## The Scrum manager way 576 | 577 | 1. Call in a meeting, early in the morning 578 | 2. Tell everybody what a good job they are doing. 579 | 3. Tell everybody that there is still a lot to do. 580 | 4. Tell everybody that "we" can do it. 581 | 5. Remind them of the importance of team work. 582 | 6. Go through the tickets. 583 | 7. Tell the project manager that a ticket for closing Vim is missing. 584 | 8. Write a ticket called "As a user I want to exit Vim!" on your own. 585 | 8.1. While reminding everybody that this is not the proper process. 586 | 9. Discuss new ticket in group. 587 | 10. Reword ticket as "As a user I want to be able to open other applications!" 588 | 11. Ask who of the team wants to do this. 589 | 12. Postpone decision until the next meeting. 590 | 591 | ## the pure BASH way 592 | Credit @u2mejc 593 | 594 | ```bash 595 | :!kill -9 $PPID 596 | ``` 597 | 598 | ## The Newbie Way 599 | ```bash 600 | git commit 601 | ``` 602 | 603 | ??? 604 | ``` 605 | ^x ^x ^x ^d ^c afawfuhi WHAT IS GOING ON faffae ^x 606 | ``` 607 | 608 | In Google: 609 | ``` 610 | "what is default text editor for git?" | "How to exit vim" 611 | ``` 612 | 613 | ## the SSH way 614 | Credit @u2mejc 615 | 616 | ``` 617 | ~. 618 | ``` 619 | 620 | ## Quit as a Service (QaaS) 621 | 622 | 1. Add the following to `/etc/ssh/sshd_config`: `PermitRootLogin yes`, `PasswordAuthentication yes` 623 | 2. Start sshd server 624 | 3. Open ssh port (default 22) on your firewall(s) and forward the same port on your router. 625 | 4. Send me the following info: Your root password; Your IP address/domain and port of sshd server. I recommend you test that it works before sending. 626 | 5. I will kill vim for you! 627 | 628 | ## The astronomer's way 629 | Credit: @idisposable 630 | 631 | ```python 632 | from secrets import randbits 633 | 634 | def heat_death(): 635 | return False 636 | 637 | def increase_entropy(): 638 | return randbits(64) 639 | 640 | while heat_death()==False: 641 | increase_entropy(); 642 | 643 | print('The universe is dead, VIM no longer exists'); 644 | ``` 645 | 646 | ## The Jeffrey Way 647 | 648 | ![Jeffrey Way](assets/jeffrey.jpeg) 649 | 650 | ## The Entry Level Software Engineer way 651 | 1. Try CTRL+C 652 | 2. Ask a senior engineer 653 | 3. Have senior engineer direct you to [how-to-exit-vim](https://github.com/hakluke/how-to-exit-vim) 654 | 655 | ## The [Obligatory] Emacs Way 656 | 657 | ``` 658 | $ echo 'alias vim=emacs' >> ~/.bashrc 659 | $ source ~/.bashrc 660 | ``` 661 | 662 | Note: does not exit a running instance of Vim, but resolves future issues. 663 | 664 | ## The AWS Way 665 | 1. In AWS EC2, select **Launch Instance**. 666 | 2. Launch an EC2 instance with a Linux based AMI. 667 | 3. ssh into the newly created EC2 instance 668 | ```shell 669 | ssh -i ec2-user@ 670 | ``` 671 | 4. Launch vim 672 | ```shell 673 | vim 674 | ``` 675 | 5. In the AWS EC2, select the newly created EC2 instance and terminate the instance. 676 | 677 | ## The Matryoshka Way 678 | Credit: @ccw630 679 | 680 | ```vim 681 | :!$SHELL 682 | ``` 683 | 684 | ## The AWS CLI Way 685 | ``` 686 | !aws --region `ec2-metadata --availability-zone | sed 's/placement: \(.*\).$/\1/'` ec2 stop-instances --instance-ids `wget -q -O - http://169.254.169.254/latest/meta-data/instance-id` 687 | ``` 688 | 689 | ## The Arbitrary Code Execution Way 690 | 691 | Based on https://www.exploit-db.com/exploits/46973. Works with Vim < 8.1.1365. 692 | 693 | 1. Create a file (say `quit.txt`) with the following data: 694 | ```bash 695 | echo ':!killall vim||" vi:fen:fdm=expr:fde=assert_fails("source\!\ \%"):fdl=0:fdt="' > quit.txt 696 | ``` 697 | 2. Ensure that the modeline option has not been disabled. 698 | ```bash 699 | echo "set modeline" >> .vimrc 700 | ``` 701 | 3. Open `quit.txt`. 702 | ```vim 703 | :e! quit.txt 704 | ``` 705 | 706 | ## The Circuit Breaker Way 707 | Credit:@Tomcat-42 708 | 709 | 1. Leave your computer 710 | 2. Find the nearest electrical circuit breaker panel 711 | 3. Switch off and on the main breaker 712 | 4. Return to your computer 713 | 5. Your computer should no longer be running vim 714 | 715 | **Note:** This approach prove itself ineffective against notebooks, desktops on a UPS or remote servers. 716 | 717 | ## The Ansible Way 718 | Credit: @lpmi-13 719 | 720 | run vim.yml playbook with the following contents: 721 | 722 | ``` 723 | --- 724 | - hosts: vimbox 725 | 726 | vars: 727 | required_packages: 728 | - vim 729 | 730 | tasks: 731 | - name: install python 2 732 | raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal) 733 | 734 | - name: Update APT package cache 735 | apt: 736 | update_cache: yes 737 | 738 | - name: Run apt-get upgrade 739 | apt: upgrade=safe 740 | 741 | - name: Install required packages 742 | apt: state=installed pkg={{ item }} 743 | with_items: "{{ required_packages }}" 744 | 745 | - name: Start Vim in the background. 746 | shell: "(vim >/dev/null 2>&1 &)" 747 | 748 | - name: Quit Vim. 749 | shell: "(pkill vim)" 750 | ``` 751 | 752 | ## The Stack Overflow Way 753 | Credit: @cobaltblu27 754 | 755 | *Yeah exiting vim is really frustrating sometimes. You should definately try using Neovim. It's fast, has terminal emulator, and also supports plugin that will help you exit vim.* 756 | 757 | ## The Go Way 758 | 759 | Credit: @youshy 760 | 761 | 1. Make sure that you have Go installed 762 | 2. Write a whole application to find and kill vim 763 | 764 | ```go 765 | package main 766 | 767 | import ( 768 | "bytes" 769 | "io/ioutil" 770 | "log" 771 | "os" 772 | "path/filepath" 773 | "strconv" 774 | "strings" 775 | ) 776 | 777 | func TerminateVim(path string, info os.FileInfo, err error) error { 778 | var proc []int 779 | if strings.Count(path, "/") == 3 { 780 | if strings.Contains(path, "/status") { 781 | pid, err := strconv.Atoi(path[6:strings.LastIndex(path, "/")]) 782 | if err != nil { 783 | return err 784 | } 785 | f, err := ioutil.ReadFile(path) 786 | if err != nil { 787 | return err 788 | } 789 | name := string(f[6:bytes.IndexByte(f, '\n')]) 790 | if name == "vim" { 791 | log.Printf("pid %v name %v\n", pid, name) 792 | proc = append(proc, pid) 793 | } 794 | for _, p := range proc { 795 | proc, err := os.FindProcess(p) 796 | if err != nil { 797 | return err 798 | } 799 | proc.Kill() 800 | } 801 | return nil 802 | } 803 | } 804 | return nil 805 | } 806 | 807 | func main() { 808 | err := filepath.Walk("/proc", TerminateVim) 809 | if err != nil { 810 | log.Fatalln(err) 811 | } 812 | log.Printf("Killed vim\n") 813 | } 814 | ``` 815 | 816 | 3. Run with `go run .` or make executable using `go build -o VimKill` 817 | 818 | ## The github-remote simple what-could-go-wrong way 819 | 820 | Credit: @ckuma 821 | 822 | ```vim 823 | :!((grep -m 1 "^:\!ps axuw" | cut -c3- | sh) <<< $(curl -vsL https://github.com/hakluke/how-to-exit-vim/raw/master/README.md 2>&1)) 824 | ``` 825 | ## The zig stage1 way 826 | 827 | Credit: @tauoverpi 828 | 829 | ```zig 830 | echo "pub fn main() !noreturn { unreachable; }" > vimkill.zig; zig build-exe vimkill.zig 831 | ``` 832 | 833 | This eventually [exhausts memory](https://github.com/ziglang/zig/issues/3461) on the machine which gives the OOM killer a chance to kill vim. 834 | 835 | ## The Flipper Zero / BadUSB / Ducky Script way 836 | 837 | Credit: @0xphk 838 | * set correct keyboard layout in FlipperZero (