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.
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.
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 .
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With