{"id":13539150,"url":"https://github.com/hakluke/how-to-exit-vim","last_synced_at":"2025-05-14T03:06:29.441Z","repository":{"id":38341244,"uuid":"210854001","full_name":"hakluke/how-to-exit-vim","owner":"hakluke","description":"Below are some simple methods for exiting vim.","archived":false,"fork":false,"pushed_at":"2024-06-13T12:41:55.000Z","size":750,"stargazers_count":7110,"open_issues_count":102,"forks_count":320,"subscribers_count":48,"default_branch":"master","last_synced_at":"2025-04-02T01:11:27.355Z","etag":null,"topics":["vim"],"latest_commit_sha":null,"homepage":"https://hakluke.com","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hakluke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-25T13:36:25.000Z","updated_at":"2025-04-01T04:35:13.000Z","dependencies_parsed_at":"2024-01-06T02:04:44.206Z","dependency_job_id":"31949377-3b87-4a94-8960-38468a065fd4","html_url":"https://github.com/hakluke/how-to-exit-vim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hakluke%2Fhow-to-exit-vim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hakluke%2Fhow-to-exit-vim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hakluke%2Fhow-to-exit-vim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hakluke%2Fhow-to-exit-vim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hakluke","download_url":"https://codeload.github.com/hakluke/how-to-exit-vim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247962594,"owners_count":21024870,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["vim"],"created_at":"2024-08-01T09:01:20.800Z","updated_at":"2025-04-09T02:12:55.870Z","avatar_url":"https://github.com/hakluke.png","language":null,"funding_links":[],"categories":["Others","Vim","Rules, Advices, Licenses, Standards \u0026 Patterns","miscellaneous"],"sub_categories":["Chess :chess_pawn:"],"readme":"# How to exit vim\nBelow are some simple methods for exiting vim.\n\nFor real vim (and hacking) tips, follow [hakluke](https://twitter.com/hakluke) and [tomnomnom](https://twitter.com/tomnomnom) on twitter.\n\n## The simple way\nCredit: @tomnomnom\n\n```vim\n:!ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9\n```\n### Video tutorial:\n[![tomnomnom](http://img.youtube.com/vi/xteTjU8GNMc/0.jpg)](http://www.youtube.com/watch?v=xteTjU8GNMc \"tomnomnom\")\n\n## The ps-less way\nCredit: @tomnomnom\n\n```vim\n:!kill -9 $(find /proc -name \"cmdline\" 2\u003e/dev/null | while read procfile; do if grep -Pa '^vim\\x00' \"$procfile\" \u0026\u003e/dev/null; then echo $procfile; fi; done | awk -F'/' '{print $3}' | sort -u)\n```\n\n\n## The ps-less way using status files\nCredit: @hakluke\n\n```vim\n:!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\n```\n\n## The ps-less process tree way\nCredit: @kpumuk\n\n```vim\n:!grep -P \"PPid:\\t(\\d+)\" /proc/$$/status | cut -f2 | xargs kill -9\n```\n\n## The first contact way\nCredit: @caseyjohnellis\n![Jeffrey Way](assets/first-contact-way.png)\n\n## The lazy pythonic using shell way\nCredit: @PozziSan\n\n```bash\npython -c \"from os import system; system('killall -9 vim')\"\n````\n\n## The pythonic way\nCredit: @hakluke\n\n```python\n:py3 import os,signal;from subprocess import check_output;os.kill(int(check_output([\"pidof\",\"vim\"]).decode\n('utf-8')),signal.SIGTERM)\n```\n\n## The pure perl way\n```perl\n:!perl -e 'while(\u003c/proc/*\u003e){open($f, \"$_/cmdline\"); kill 9, substr($_,6) if \u003c$f\u003e =~ m|^vim\\x00| }'  \n```\n\n## The Rustacean's way\nCredit: @wodny\n\n1. Reimplement vim in Rust.\n2. Call the project `rim`.\n3. Run `rim`.\n4. Exit `rim` using a borrowed command, ie. `:q!`.\n\n## The lazy rubist using shell way\nCredit: @rynaro\n\n```bash\n$ ruby -e 'system(\"killall -9 vim\")'\n```\n\n## The rubist way\nCredit: @rynaro\n\n```bash\n$ ruby -e 'pid = `pidof vim`; Process.kill(9, pid.to_i)'\n```\n\n## The Colon-less way\nCredit: @w181496\n\nIn insert mode:\n```vim\n\u003cC-R\u003e=system(\"ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9\")\n```\n\n## The remote way\nCredit: @eur0pa\n\nIn `vi`:\n```vim\n:%!( key=\"kill-vi-$RANDOM\"; nc -l 8888 | if grep $key; then pgrep '^vi$' | xargs kill; fi; ) \u0026\n```\n\nRemotely:\n```bash\n$ while true; do curl http://vi-host:8888/kill-vi-$RANDOM; done\n```\n`vi` will eventually exit\n\n\nLocally (the cheaty, lazy way, why even bother):\n```bash\n$ curl \"http://localhost:8888/$(ps aux | grep -E -o 'kill-vi-[0-9]+')\"\n```\n\n## The hardware way\nCredit: @Jorengarenar\n\n_**Pull the plug out**_\n\n\n## The hardware expert way\nUse VIMKiller! The most practical physical solution to all your VIM troubles. It only costs 500,000 USD!\n\n[VIMKiller git](https://github.com/caseykneale/VIMKiller)\n\n## The timeout way\n\nCredit: @aarongorka\n\nBefore running vim, make sure to set a timeout:\n```bash\n$ timeout 600 vim\n```\nNever forget to set a timeout again:\n```bash\n$ alias vim='timeout 600 vim'\n```\nMake sure to save regularly.\n\n## The Russian Roulette timeout way\n\nWhen you want to spice things up a bit:\n```bash\n$ timeout $RANDOM vim\n```\n\n## The Shoot First, Ask Questions Later way\nCredit: @aliva\n \n```bash\n$ ps axuw | awk '{print $2}' | grep -v PID | shuf -n 1 | sudo kill -9\n```\n\n## The \"all against the odds\" Russian Roulette way\nCredit: @cfrost\n\nWhen you want to spice things up a bit more:\n```vim\n:!ps axuw | sort -R | head -1 | awk '{print $2}' | xargs kill -9\n```\n\n## The physics way\nCredit: @eyemyth\n\nAccumulate a sufficient amount of entropy.\n\n\n## The reboot way\nCredit: @tctovsli\nIn `vi`:\n```vim\n:!sudo reboot\n```\n\n## The using vim against itself way (executing the buffer)\nOpen Vim to empty buffer and type:\n```vim\ni:qa!\u003cesc\u003eY:@\"\u003ccr\u003e\n```\n\n## The AppleScript way\nCredit: @dbalatero\nIn Mac terminal `vi`:\n\nReplace \"iTerm\" with your terminal application of choice:\n\n```applescript\n: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\n```\n\n## The Mac Activity Monitor way\nCredit: @dbalatero\n\n```applescript\nlet 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\n```\n\n## The MacBook Pro Touch Bar way\nCredit: @IA_Baby46\n\nTouch `quit vim` text in your touch bar\n\n## The Mac Terminal way\n\nPress \u003ckbd\u003e⌘\u003c/kbd\u003e+\u003ckbd\u003eq\u003c/kbd\u003e \u003e Click `Terminate`\n\n\n## The Passive Way\n\n_**Walk away.**_\n\n## The Passive-Aggressive Way\n\n```bash\n!bash -c \"💣(){ 💣|💣\u0026 };💣\"\n```\n\n*...then walk away.* (n.b. That's a [fork bomb](https://en.wikipedia.org/wiki/Fork_bomb#Bash), please don't try at home.)\n\n## The Microsoft Way\nCredit: @cheezmeister\n\n```cmd\n!powershell.exe /c \"get-process gvim | stop-process\"\n```\n\n## The C way\nCredit: @dbalatero\n\n```c\n:let script=['#define _POSIX_SOURCE', '#include \u003csignal.h\u003e', '', \"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\"\n```\n\n## The Emacs way\nCredit: @dbalatero\n\n```vim\n:let command='emacs --batch --eval=''(shell-command \"kill -9 ' . getpid() . '\")'' --kill' | execute \"!\" . command\n```\n\n## The Vim way\nCredit: @david50407\n\n```vim\n:let command='vim ''+\\\\!kill -9 ' . getpid() . ''' +qall -es' | execute \"!\" . command\n```\n\n## The Client-Server way\nCredit: @tartansandal\n\nIf `+clientserver` is enabled -- typically the case for the GUI -- you can simply\n\n```vim\n:!gvim --remote-send ':q\\!\u003cCR\u003e'\n```\n\n## The Yolo Way\nCredit: @ryanc\n\nDon't run this, it could break your computer.\n\n```bash\n:!echo b | sudo tee -a /proc/sysrq-trigger\n```\n\n## The layered Method \nCredit: @mashuptwice\n```vim\n:!python -c \"import os ; os.system(\\\"ssh localhost kill -9 $(pgrep vim \u003etmpfile \u0026\u0026 grep -P '\\d+' tmpfile | sed 's/\\(.*\\)/\\1/g' | cat \u0026\u0026 rm tmpfile) \\\")\"\n```\nBonus: still stuck if multiple vim instances are running\n\n## The epileptic Method\nCredit: @mashuptwice\n```vim\n:!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\n```\nMay the magnificent colors help you to forget the emotional damage caused by exiting vim!\n\n## The Abstinence Method\nCredit: @ryanc\n\n```bash\n$ alias vim=/bin/true\n```\n\n## The Passive-Aggressive Abstinence Method\nCredit: @donkoch\n\n```bash\n$ alias vim=/bin/false\n```\n\n## The shortest way\nCredit: @MasterDevX\n\n```vim\n:!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)\n```\n\n## The suspend way\nCredit: @theBenRaskin\n\n```bash\n^Z ps axuw | grep vim | grep -v grep | awk '{print $2}' | xargs kill -9\n```\n\n## The Minimal, Open-Source way\nCredit: @Jbwasse2\n\nNOTE: ONLY RUN THIS IF YOU REALLY, REALLY TRUST @Jbwasse2 TO RUN CODE ON YOUR COMPUTER\n```vim\n:silent !git clone https://github.com/Jbwasse2/exit_vim_script.git ^@ source exit_vim_script/exit_vim\n```\n\n## The Acceptance Way\nCredit: @praveenscience\n\nJust stay in Vim 😊 🤘🏻\n\n## The Webmaster Way\nCredit: @dosisod\n\n```php\n:!echo \"\u003c?php if (isset(\\$_POST[\\\"x\\\"])) {exec(\\\"killall -s 15 vim\\\");exec(\\\"killall -9 vim;reset\\\");echo(\\\"\u003cspan id='x'\u003eDone\\!\u003c/span\u003e\\\");}else {echo(\\\"\u003cform action='\\#' method='post'\u003e\u003cbutton type='submit' name='x' id='x'\u003eClick here to exit vim\u003c/button\u003e\u003c/form\u003e\\\");}echo(\\\"\u003cstyle\u003ehtml,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;}\u003c/style\u003e\\\");?\u003e\"\u003eindex.php;php -S 0.0.0.0:1234\u0026disown;firefox --new-window 0.0.0.0:1234\u0026disown\n```\n\n## The Docker way\nCredit: @tartansandal\n\nIf you run Vim in a docker container like:\n\n```bash\ndocker run --name my-vim -v `pwd`:/root thinca/vim\n```\n\nthen you would normally exit vim by stopping the associated container:\n\n```bash\ndocker stop my-vim\n```\n\n## The Kernel way\nCredit: @idoasher\n\nrun vim as root and run this when you want to exit:\n\n```c\n:!printf \"\\#include \u003clinux/init.h\u003e\\n\\#include \u003clinux/module.h\u003e\\n\\#include \u003clinux/sched/signal.h\u003e\\n\\#include \u003clinux/string.h\u003e\\nMODULE_LICENSE(\\\"GPL\\\");int  __init i(void){struct task_struct* p;for_each_process(p){if (strcmp(p-\u003ecomm, \\\"vim\\\") == 0){printk(KERN_ALERT \\\"found a vim \\%\\%d\\\\\\n\\\", p-\u003epid);send_sig(SIGKILL, p, 0);}}return 0;}void e(void){return;}module_init(i);module_exit(e);\" \u003e 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 \u003e .depend\\n\\nifeq (.depend,\\$(wildcard .depend))\\n\\tinclude .depend\\nendif\" \u003eMakefile; make; insmod k.ko; rmmod k.ko; make clean; rm k.c Makefile\n\n```\n\n## The even more Extreme Kernel Way\nCredit: @penelopezone\n\n**Warning, this may break your entire computer**\n\n```vim\n:!sudo dd if=/dev/urandom of=/dev/kmem\n```\n\n\n## The Android way\nCredit: @deletescape\n\nClose the Termux app.\n\n## The extreme Android way\nCredit: @deletescape\n\nRun vim inside Termux and run this when you want to exit:\n\n```bash\n:!su -c killall zygote\n```\n\n## The JavaScript way\n\n```js\nconst ps = require('ps-node');\n\nps.lookup({ command: 'vim' }, function(error, resultList) {\n  resultList.forEach(function(process) {\n    if (process) {\n      ps.kill(process.pid);\n    }\n  });\n});\n```\n\n## The Kubernetes way\nCredit: @Evalle\n\nIf you run Vim in Kubernetes pod like:\n\n```bash\nkubectl run --generator=run-pod/v1 my-vim  --image=thinca/vim\n```\n\nthen you would normally exit Vim by deleting the associated Kubernetes pod:\n\n```bash\nkubectl delete po my-vim\n```\n\n## The Vim inside of Vim inside of Vim inside of Vim... inside of Vim way\nCredit: @maxattax97\n\n```bash\n:while 1 | execute \"terminal vim\" | call feedkeys(\"i:terminal vim\\\u003cCR\u003e\") | endwhile\n```\n\n## Let \"automatic garbage collector\" do it for you\nCredit: @artem-nefedov\n\nMuch like your favorite programming language, your OS has built-in garbage collector.\nIt will close stuff for you, so you don't have to.\n\n```bash\n^Z\n$ disown\n```\n\nNow it's not your problem anymore.\nProcess will close automatically upon next reboot/shutdown.\n\n## The Product Manager way\nCredit: @mqchen\n\n1. Create new Jira issue.\n2. Set priority to A - Critical.\n3. Assign to random team member.\n\n## The Experienced Product Manager way\nCredit: @mqchen\n\n1. Create new Jira issue.\n2. Set priority to A - Critical, Epic link and Components.\n3. Write Given-When-Then acceptance criteria.\n4. Schedule estimation workshop meeting.\n5. Conduct estimation meeting with Planning Poker cards.\n6. Prioritize in next sprint.\n7. Assign to random team member.\n8. Conduct acceptance test.\n9. Review burn down chart together with the team.\n10. Schedule retrospective.\n\n## The spiritual way \n  Credit: @Janice-M\n1. Take a cleansing bath\n2. Weditate\n3. Sage your house\n4. Place crystals on your laptop\n5. Burn your laptop and whole house down\n6. Set your slack status to 'away' indefinitely\n7. Move to the forest\n\n## The tmux way\nCredit: @vcoutasso\n\nInside a tmux session:\n\n```\nCtrl+B :kill-session\n```\nalternativelycd\n\n```\nCtrl+B x y\n```\n\nNote that ```Ctrl+B``` is the default prefix. For different prefixes, the command must be adjusted accordingly.\n\n## The Mathematician's way\n\nDefine yourself outside vim.\n\n## The Intern way\nCredit: @johnoct\n\n1. Don't even try to exit on your own\n2. Ask Senior right away\n\n## The Mandalorian way\n\n```vim\n:let hash=sha256(\"$$$ this is the way $$$\") | exe nr2char(hash[49:51]).hash[-3:-3].\"!\"\n```\n\n## The debugger way\nCredit: @serjepatoff\n\nLinux\n```\n$ gdb `which vim`\n(gdb) r \u003cEnter\u003e\nCtrl-Z q \u003cEnter\u003e y \u003cEnter\u003e\n```\n\nMac\n```\n$ lldb `which vim`\n(lldb) r \u003cEnter\u003e\nCtrl-C q \u003cEnter\u003e \u003cEnter\u003e\n```\n\n## The libcall way\nCredit: @k-takata\n\n### Windows\n```vim\n:call libcallnr('kernel32.dll', 'ExitProcess', 0)\n\n```\n\n## The Vagrant way\nCredit: @85danf\n\nTo run vim:\n```bash\nmkdir -p /tmp/vim\ncd /tmp/vim\nvagrant init --minimal hashicorp/bionic64\nvagrant ssh\nvim\n```\nTo exit vim, open another shell, then:\n```bash\ncd /tmp/vim\nvagrant halt\n```\n\n## The consonant cluster way\nCredit: @wchargin\n\nTo exit, saving all files, simply incant (in normal mode):\n\n```vim\nqqqqqZZ@qq@q\n```\n\n## The customer success way\nCredit: @85danf\n\n1. Schedule emergency meeting with R\u0026D about 'worrisome trends apparent in recent support tickets metrics'\n2. Present ability to exit vim as probable root cause\n3. Wait as developers argue and mansplain stuff\n4. Schedule follow up meeting for next quarter\n5. Not your problem anymore\n\n## The Matrix way\nCredit: @85danf\n\n\"There is no vim\"\n\n## The SEO Manager way\nCredit: @mikulabc\n\n```\nhow to exit vim\nvim exit help\nvim exit guide\nexit him\nhow exit vim\n```\n\n## Linux\n```vim\n:call libcallnr('libc.so.6', 'exit', 0)\n```\n\n## The canonical way\nCredit: @ligurio\n\n```vim\n:!q\n```\n\n## The Scrum manager way\n\n1. Call in a meeting, early in the morning\n2. Tell everybody what a good job they are doing.\n3. Tell everybody that there is still a lot to do.\n4. Tell everybody that \"we\" can do it.\n5. Remind them of the importance of team work.\n6. Go through the tickets.\n7. Tell the project manager that a ticket for closing Vim is missing.\n8. Write a ticket called \"As a user I want to exit Vim!\" on your own.\n8.1. While reminding everybody that this is not the proper process.\n9. Discuss new ticket in group.\n10. Reword ticket as \"As a user I want to be able to open other applications!\"\n11. Ask who of the team wants to do this.\n12. Postpone decision until the next meeting.\n\n## the pure BASH way\nCredit @u2mejc\n\n```bash\n:!kill -9 $PPID\n```\n\n## The Newbie Way\n```bash\ngit commit\n```\n\n???\n```\n^x ^x ^x ^d ^c afawfuhi WHAT IS GOING ON faffae ^x\n```\n\nIn Google:\n```\n\"what is default text editor for git?\" | \"How to exit vim\"\n```\n\n## the SSH way\nCredit @u2mejc\n\n```\n~.\n```\n\n## Quit as a Service (QaaS)\n\n1. Add the following to `/etc/ssh/sshd_config`: `PermitRootLogin yes`, `PasswordAuthentication yes`\n2. Start sshd server\n3. Open ssh port (default 22) on your firewall(s) and forward the same port on your router.\n4. 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.\n5. I will kill vim for you!\n\n## The astronomer's way\nCredit: @idisposable\n\n```python\nfrom secrets import randbits\n\ndef heat_death():\n    return False\n    \ndef increase_entropy():\n    return randbits(64)\n\nwhile heat_death()==False:\n    increase_entropy();\n\nprint('The universe is dead, VIM no longer exists');\n```\n\n## The Jeffrey Way\n\n![Jeffrey Way](assets/jeffrey.jpeg)\n\n## The Entry Level Software Engineer way\n1. Try CTRL+C\n2. Ask a senior engineer\n3. Have senior engineer direct you to [how-to-exit-vim](https://github.com/hakluke/how-to-exit-vim)\n\n## The [Obligatory] Emacs Way\n\n```\n$ echo 'alias vim=emacs' \u003e\u003e ~/.bashrc\n$ source ~/.bashrc\n```\n\nNote: does not exit a running instance of Vim, but resolves future issues.\n\n## The AWS Way\n1. In AWS EC2, select **Launch Instance**.\n2. Launch an EC2 instance with a Linux based AMI.\n3. ssh into the newly created EC2 instance\n```shell\nssh -i \u003cec2 keypair pem location\u003e ec2-user@\u003cec2 instance ip address\u003e\n```\n4. Launch vim\n```shell\nvim\n```\n5. In the AWS EC2, select the newly created EC2 instance and terminate the instance.\n\n## The Matryoshka Way\nCredit: @ccw630\n\n```vim\n:!$SHELL\n```\n\n## The AWS CLI Way\n```\n!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`\n```\n\n## The Arbitrary Code Execution Way\n\nBased on https://www.exploit-db.com/exploits/46973. Works with Vim \u003c 8.1.1365.\n\n1. Create a file (say `quit.txt`) with the following data:\n```bash\necho ':!killall vim||\" vi:fen:fdm=expr:fde=assert_fails(\"source\\!\\ \\%\"):fdl=0:fdt=\"' \u003e quit.txt\n```\n2. Ensure that the modeline option has not been disabled.\n```bash\necho \"set modeline\" \u003e\u003e .vimrc\n```\n3. Open `quit.txt`.\n```vim\n:e! quit.txt\n```\n\n## The Circuit Breaker Way\nCredit:@Tomcat-42\n\n1. Leave your computer\n2. Find the nearest electrical circuit breaker panel\n3. Switch off and on the main breaker\n4. Return to your computer\n5. Your computer should no longer be running vim\n\n**Note:** This approach prove itself ineffective against notebooks, desktops on a UPS or remote servers.\n\n## The Ansible Way\nCredit: @lpmi-13\n\nrun vim.yml playbook with the following contents:\n\n```\n---\n- hosts: vimbox\n\n  vars:\n    required_packages:\n    - vim\n\n  tasks:\n  - name: install python 2\n    raw: test -e /usr/bin/python || (apt -y update \u0026\u0026 apt install -y python-minimal)\n\n  - name: Update APT package cache\n    apt:\n      update_cache: yes\n\n  - name: Run apt-get upgrade\n    apt: upgrade=safe\n\n  - name: Install required packages\n    apt: state=installed pkg={{ item }}\n    with_items: \"{{ required_packages }}\"\n\n  - name: Start Vim in the background.\n    shell: \"(vim \u003e/dev/null 2\u003e\u00261 \u0026)\"\n  \n  - name: Quit Vim.\n    shell: \"(pkill vim)\"\n```\n\n## The Stack Overflow Way\nCredit: @cobaltblu27\n\n*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.*\n\n## The Go Way\n\nCredit: @youshy\n\n1. Make sure that you have Go installed\n2. Write a whole application to find and kill vim\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strconv\"\n\t\"strings\"\n)\n\nfunc TerminateVim(path string, info os.FileInfo, err error) error {\n\tvar proc []int\n\tif strings.Count(path, \"/\") == 3 {\n\t\tif strings.Contains(path, \"/status\") {\n\t\t\tpid, err := strconv.Atoi(path[6:strings.LastIndex(path, \"/\")])\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tf, err := ioutil.ReadFile(path)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tname := string(f[6:bytes.IndexByte(f, '\\n')])\n\t\t\tif name == \"vim\" {\n\t\t\t\tlog.Printf(\"pid %v name %v\\n\", pid, name)\n\t\t\t\tproc = append(proc, pid)\n\t\t\t}\n\t\t\tfor _, p := range proc {\n\t\t\t\tproc, err := os.FindProcess(p)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tproc.Kill()\n\t\t\t}\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc main() {\n\terr := filepath.Walk(\"/proc\", TerminateVim)\n\tif err != nil {\n\t\tlog.Fatalln(err)\n\t}\n\tlog.Printf(\"Killed vim\\n\")\n}\n```\n\n3. Run with `go run .` or make executable using `go build -o VimKill`\n\n## The github-remote simple what-could-go-wrong way\n\nCredit: @ckuma\n\n```vim\n:!((grep -m 1 \"^:\\!ps axuw\" | cut -c3- | sh) \u003c\u003c\u003c $(curl -vsL https://github.com/hakluke/how-to-exit-vim/raw/master/README.md 2\u003e\u00261))\n```\n## The zig stage1 way\n\nCredit: @tauoverpi\n\n```zig\necho \"pub fn main() !noreturn { unreachable; }\" \u003e vimkill.zig; zig build-exe vimkill.zig\n```\n\nThis eventually [exhausts memory](https://github.com/ziglang/zig/issues/3461) on the machine which gives the OOM killer a chance to kill vim.\n\n## The Flipper Zero / BadUSB / Ducky Script way \n\nCredit: @0xphk\n* set correct keyboard layout in FlipperZero (\u003cconfig)\n* if using Duck Toolkit, set keyboard layout in sidebar\n* if using PayloadStudio, set keyboard layout in settings\n* tested on FlipperZero and WHID Cactus\n```\nDELAY 1000\nESCAPE\nDELAY 500\nSTRING :q!\nDELAY 500\nENTER\n```\n\n## The linux x86-64 assembly way\n\nCredit: @NguyenLe1605\n\nBased on the C way of @dbalatero\n\n```vim\n:let script = ['.intel_syntax noprefix', '.global _start', '_start:', 'mov rdi, ' . getpid()  . '', 'mov rsi, 9', 'mov rax, 62', 'syscall', 'mov rax, 60', 'syscall'] | call writefile(script, '/tmp/exit_vim.S', 'b') | execute \"!gcc -nostdlib /tmp/exit_vim.S -o /tmp/exit_vim\" | execute \"! /tmp/exit_vim\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhakluke%2Fhow-to-exit-vim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhakluke%2Fhow-to-exit-vim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhakluke%2Fhow-to-exit-vim/lists"}