in ,

hakluke / how-to-exit-vim, Hacker News

hakluke / how-to-exit-vim, Hacker News


    

Below are some simple methods for exiting vim.

For real vim (and hacking) tips, followhaklukeandtomnomnomon twitter.

************************

Credit: @tomnomnom

axuw |
grep
vim
|
grep
******************* (v)  grep
| awk
' {print $ 2}
****************** xargs kill
- 9
)

The ps-less way

Credit: @tomnomnom

kill  - 9
************** ($) ******************  find
(dev  / / null | while read procfile; do if grep -Pa '^ vim  x  '' $ procfile '&>/dev
/ null; then echo $ procfile; fi; done | awk - F '/
********************* ({********************) print
$ 3 (**********************} '|
(sort
-
u
)

************************The ps-less way using status files

Credit: @hakluke

^
 /
proc
 /
//
(g
******************** '
| sed'
s
/ \/.*/

/ (g) '; done | xargs kill

- 9
)

The ps-less process tree way

Credit: @kpumuk

PPid:   t

(

 d

)

/ proc /
$$
/ status | cut-
f2 | xargs kill
- 9
)

**************************

The pythonic way

Credit: @hakluke

: py3 (import) ******************** (os, signal; (from

(subprocess) ******************* (import) ******************** (check_output; os.kill)
int
(check_output (["pidof","vim"]). decode (
(utf-8) ****************************************** () ************** signal.  SIGTERM
)

**********

Credit: @w

In insert mode:

The remote way

Credit: @ eur0pa

In

********************** (key) ********************************=
kill-vi- $ RANDOM
********************** (n ************** nc

********** -

l
if

grep $ key
; then pgrep
^ vi $
'| xargs kill; fi;) &

************

Remotely:

************** (while
) ********************* (true) ;

******************** (docurl http: // vi-host: 181496 / kill-vi -$ RANDOM
)

vi

************************ will eventually exit

Locally (the cheaty, lazy way, why even bother):

$ curl

************************ http: // localhost: /

$ (

ps auxgrep -E -o'
"

The hardware way

Credit: @Jorengarenar

******************************** Pull the plug out**************************

The timeout way

Credit: @aarongorka

Before running vim, make sure to set a timeout:

Never forget to set a timeout again:

************** (alias) ******************** (vim=

Make sure to save regularly.

When you want to spice things up a bit:

The physics way

Credit: @eyemyth

Accumulate a sufficient amount of entropy.

The reboot way

Credit: @tctovsli In

The using vim against itself way (executing the buffer)

Open Vim to empty buffer and type:

"x"].

Credit: @dbalatero In Mac terminal vi (********************************:

Replace "iTerm" with your terminal application of choice:

************************=

************************** (activate application********************** (iTerm) ******************** n n (tell application

" (System Events) ******************** " n (keystroke) :

" n (keystroke) ************************************** (q) ****************** ( " n) ******************** (keystroke) **************************************** a

 " nkeystroke
“!” ****************** " n
key code (n  **************** (end tell
)
tmp/
(exit
-
vim.scpt

**********

Credit: @dbalatero

letlet (script) ****************************** (=**********************

******************** (activate application

************************ (Activity Monitor) ******************** " n (tell application " (System Events) ******************** " n t (keystroke) ************************************** (f) using {option down, command down} n tkeystroke "

vim  " n  n  t
tell 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 t
key code
 n  t  t
end tell n  t
end tell n
end tell   n
**********************

call writefile (split (script, " n", 1), '/tmp/exit-vim.scpt', 'b') | ! osascript

/
tmp/
(exit
-
vim.scpt

************

******************************** Walk away. (************************************

************

**************************

... then walk away.(nb That's a (fork bomb) , please don't try at home.)

**************

**************************

Credit: @cheezmeister

! powershell.exe / c (************************************ get-process gvim | stop-process

"

**************

The C way

Credit: @dbalatero

: let script=['#define _POSIX_SOURCE','#include','',"int main() {","kill(". getpid() .", SIGKILL);",'return 0;','}'] | callwritefile
( script,

' / tmp / exit_vim.c

'

),
******************** (b) ******************** ["pidof","vim"] ********************| execute "! gcc /tmp/exit_vim.c -o / tmp / exit_vim" | execute "! / tmp / exit_vim"

****************

********** The Emacs way

Credit: @dbalatero

************** (command) ******************************** (=********************)

emacs --batch --eval=

''  (shell-command "kill -9
) ****************** (getpid)
******************** ()********************* --kill
. **************
execute
************************
command

****************

Credit: @david

************** (command) ******************************** (=********************)

vim

  \! kill -9
'

.
getpid
() .
********************
**********************
execute
************************
command

******************

Credit: @tartansandal

If

(remote) ********************* - send************: q !