Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you quit the Vi editor with single keypress?

Because honestly

:wq!

is just too much to type.

Please note that the question is about original Vi (say Vi which comes with FreeBSD) not Vim.

like image 341
dolzenko Avatar asked Jan 22 '09 12:01

dolzenko


People also ask

How do I quit vi editor?

Press Esc to enter Command mode, and then type :wq to write and quit the file. The other, quicker option is to use the keyboard shortcut ZZ to write and quit. To the non-vi initiated, write means save, and quit means exit vi.

How do I save and exit vi editor?

Save a File and Quit Vim / Vi To save the file and exit the editor simultaneously, press Esc to switch to normal mode, type :wq and hit Enter . Another command to save a file and quit Vim is :x .

How do I get out of insert mode in vi editor without escape?

First, press the Esc key a few times. This will ensure vi is out of Insert mode and in Command mode. Second, type :q! and press Enter. This tells vi to quit without saving any changes.


2 Answers

Hold down the shift key and bang on Z twice.

ZZ is (mostly) equivalent to :wq!.

If you really want a single-keystroke solution, FreeBSD comes with the source so, in a pinch, you could modify that and re-compile. It's a bit of an overkill but it'll solve your problem.

like image 108
paxdiablo Avatar answered Oct 10 '22 14:10

paxdiablo


This seems to work on solaris' old version of vi:

Version SVR4.0, Solaris 2.5.0

$ vi -c "map g ZZ" test

edit: Also, this seems to work:

$ vi -c 'map g :q!^M' test

Where ^M is actually, ^V (ctl-v) then ^M (ctl-m)

like image 42
Dan McNevin Avatar answered Oct 10 '22 12:10

Dan McNevin