How do you quit the Vi editor with single keypress?

送分小仙女□ 提交于 2019-12-21 09:27:36

问题


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.


回答1:


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)




回答2:


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.




回答3:


What about "ZZ"? It has slightly different semantics to ":wq!", but is also slightly shorter.




回答4:


Map your favourite key to the :wq! command.

e.g. put this in your .vimrc:

map <F8> :wq!<CR>

Et voilá.

Edit: Sorry, vim only, missed that.




回答5:


Does :x work on Vi? Although for your case I guess it might be :x!




回答6:


If you're using gvim you can close it with ALT+F4. Two keys, but one keypress.

If you're using vi in its own xterm, ALT+F4 should close the xterm, killing vi as well.




回答7:


What's wrong with the tried and true?

:x

It's not one key press, but it's much less than :wq! which is what your question appears to truly seek.

Or is this a ViM only feature? My apologies if so.



来源:https://stackoverflow.com/questions/468939/how-do-you-quit-the-vi-editor-with-single-keypress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!