{"id":4944,"date":"2024-10-24T09:47:49","date_gmt":"2024-10-24T09:47:49","guid":{"rendered":"https:\/\/howtogeek.blog\/zh\/?p=4944"},"modified":"2024-10-24T09:47:49","modified_gmt":"2024-10-24T09:47:49","slug":"stepbystep-guide-how-to-exit-vi-editor-in-linux","status":"publish","type":"post","link":"https:\/\/howtogeek.blog\/zh\/stepbystep-guide-how-to-exit-vi-editor-in-linux\/","title":{"rendered":"\u9010\u6b65\u6307\u5357\uff1a\u5982\u4f55\u5728 Linux \u4e2d\u9000\u51fa vi \u7de8\u8f2f\u5668"},"content":{"rendered":"<p>\u5c0d\u65bc Linux \u65b0\u624b\u4f86\u8aaa\uff0c<code>vi<\/code>\u7531\u65bc\u5176\u7368\u7279\u7684\u6a21\u5f0f\u548c\u547d\u4ee4\u7d50\u69cb\uff0c\u96e2\u958b\u7de8\u8f2f\u5668\u901a\u5e38\u6703\u611f\u5230\u56f0\u60d1\u3002\u7121\u8ad6\u60a8\u6253\u7b97\u4fdd\u5b58\u9032\u5ea6\u9084\u662f\u5b8c\u5168\u653e\u68c4\u66f4\u6539\uff0c\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u9000\u51fa\u90fd\u5f88\u91cd\u8981\u3002<\/p>\n<h2 id=\"vi-modes\">\u4e0d\u540c\u7684\u6a21\u5f0f<code>vi<\/code><\/h2>\n<p>\u6b64<code>vi<\/code>\u7de8\u8f2f\u5668\u4e3b\u8981\u4ee5\u5169\u7a2e\u4e3b\u8981\u6a21\u5f0f\u904b\u4f5c\uff1a<\/p>\n<ul>\n<li><strong>\u547d\u4ee4\u6a21\u5f0f\uff1a<\/strong>\u6b64\u6a21\u5f0f\u7528\u65bc\u5c0e\u822a\u548c\u57f7\u884c\u4e0d\u540c\u7684\u547d\u4ee4\u3002<\/li>\n<li><strong>\u63d2\u5165\u6a21\u5f0f\uff1a<\/strong>\u6b64\u6a21\u5f0f\u53ef\u8b93\u60a8\u65b0\u589e\u548c\u4fee\u6539\u6587\u5b57\u3002<\/li>\n<\/ul>\n<p>\u7576\u60a8\u958b\u555f \u6642<code>vi<\/code>\uff0c\u5b83\u9810\u8a2d\u70ba\u547d\u4ee4\u6a21\u5f0f\u3002\u82e5\u8981\u5207\u63db\u5230\u63d2\u5165\u6a21\u5f0f\uff0c\u8acb\u6309<code>i<\/code>\u3002\u82e5\u8981\u5f9e\u63d2\u5165\u6a21\u5f0f\u8fd4\u56de\u547d\u4ee4\u6a21\u5f0f\uff0c\u53ea\u9700\u6309\u5373\u53ef<code>Esc<\/code>\u3002<\/p>\n<h2 id=\"saving-changes-and-exiting-vi\">\u5982\u4f55\u5132\u5b58\u8b8a\u66f4\u4e26\u9000\u51fa<code>vi<\/code><\/h2>\n<ul>\n<li>\u9996\u5148\uff0c\u6309<code>Esc<\/code>\u9032\u5165\u547d\u4ee4\u6a21\u5f0f\u3002<\/li>\n<li>\u7136\u5f8c\uff0c\u9375\u5165<code>:wq<\/code>\u4e26\u9ede\u64ca<code>Enter<\/code>\u3002<\/li>\n<\/ul>\n<p>\u6b64\u5e8f\u5217\u5c07\u4fdd\u5b58\u60a8\u7684\u4fee\u6539\u4e26\u95dc\u9589\u7de8\u8f2f\u5668\u3002<\/p>\n<h2 id=\"exiting-vi-without-saving-changes\">\u95dc\u9589<code>vi<\/code>\u800c\u4e0d\u5132\u5b58\u66f4\u6539<\/h2>\n<ul>\n<li>\u6309\u6b64\u9375<code>Esc<\/code>\u5207\u63db\u5230\u6307\u4ee4\u6a21\u5f0f\u3002<\/li>\n<li>\u9375\u5165<code>:q!<\/code>\u4e26\u6309<code>Enter<\/code>\u3002<\/li>\n<\/ul>\n<p>\u6b64\u65b9\u6cd5\u5c07\u9000\u51fa\uff0c<code>vi<\/code>\u800c\u4e0d\u4fdd\u7559\u6703\u8a71\u671f\u9593\u6240\u505a\u7684\u4efb\u4f55\u8b8a\u66f4\u3002<\/p>\n<h2 id=\"alternative-command-for-saving-and-exiting\">\u53e6\u4e00\u7a2e\u4fdd\u5b58\u4e26\u9000\u51fa\u7684\u65b9\u6cd5<\/h2>\n<ul>\n<li>\u6309 \u78ba\u8a8d\u60a8\u8655\u65bc\u547d\u4ee4\u6a21\u5f0f<code>Esc<\/code>\u3002<\/li>\n<li>\u7136\u5f8c\uff0c\u8f38\u5165<code>:x<\/code>\u4e26\u6309<code>Enter<\/code>\u3002<\/li>\n<\/ul>\n<p>\u53ea\u6709\u7576\u66f4\u6539\u5b58\u5728\u6642\uff0c\u8a72<code>:x<\/code>\u547d\u4ee4\u624d\u6703\u4fdd\u5b58\u9019\u4e9b\u66f4\u6539\uff0c\u7136\u5f8c\u9000\u51fa<code>vi<\/code>\u3002<\/p>\n<h2 id=\"quitting-vi-using-shortcut-keys\"><code>vi<\/code>\u4f7f\u7528\u5feb\u6377\u9375\u9000\u51fa<\/h2>\n<ul>\n<li>\u6309<code>Esc<\/code>\u9032\u5165\u547d\u4ee4\u6a21\u5f0f\u3002<\/li>\n<li>\u6309<code>Shift<\/code>+<code>Z<\/code>\u5169\u6b21 ( <code>ZZ<\/code>) \u5132\u5b58\u4e26\u9000\u51fa\u3002<\/li>\n<\/ul>\n<p>\u4f7f\u7528<code>ZZ<\/code>\u5c07\u7acb\u5373\u5132\u5b58\u60a8\u7684\u8b8a\u66f4\u4e26\u95dc\u9589\u7de8\u8f2f\u5668\u3002<\/p>\n<h2 id=\"exiting-when-esc-key-does-not-work\"><code>Esc<\/code>\u5982\u679c\u9470\u5319\u5931\u9748\u600e\u9ebc\u8fa6<\/h2>\n<p>\u5982\u679c<code>Esc<\/code>\u6309\u9375\u4e0d\u8d77\u4f5c\u7528\uff0c\u8acb\u5617\u8a66\u4ee5\u4e0b\u66ff\u4ee3\u65b9\u6cd5\u4f86\u9032\u5165\u547d\u4ee4\u6a21\u5f0f\uff1a<\/p>\n<ul>\n<li>\u6309<code>Ctrl<\/code>+ <code>[<\/code>\u3002<\/li>\n<li>\u6309<code>Ctrl<\/code>+ <code>C<\/code>\u3002<\/li>\n<\/ul>\n<p>\u6210\u529f\u5207\u63db\u5230\u547d\u4ee4\u6a21\u5f0f\u5f8c\uff0c\u60a8\u53ef\u4ee5\u57f7\u884c\u5c0d\u61c9\u7684\u547d\u4ee4\u9000\u51fa<code>vi<\/code>\u3002<\/p>\n<h2 id=\"troubleshooting-common-issues\">\u89e3\u6c7a\u5e38\u898b\u554f\u984c<\/h2>\n<p>\u5982\u679c\u60a8\u5728\u5617\u8a66\u9000\u51fa\u6642\u9047\u5230\u932f\u8aa4\u8a0a\u606f\uff0c\u4f8b\u5982\uff1a<\/p>\n<p> <code>E37: No write since last change (add!  to override)<\/code><\/p>\n<p>\u9019\u8868\u793a\u9084\u6709\u5c1a\u672a\u5132\u5b58\u7684\u8b8a\u66f4\u3002\u82e5\u8981\u9000\u51fa\u4e0d\u5132\u5b58\uff0c\u8acb\u4f7f\u7528<code>:q!<\/code>.\u82e5\u8981\u5132\u5b58\u60a8\u7684\u5de5\u4f5c\u4e26\u9000\u51fa\uff0c\u8acb\u9078\u64c7<code>:wq<\/code>\u6216<code>ZZ<\/code>\u3002<\/p>\n<p>\u719f\u6089\u6b63\u78ba\u7684\u9000\u51fa\u7a0b\u5e8f<code>vi<\/code>\u53ef\u4ee5\u589e\u5f37\u60a8\u7684\u6574\u9ad4\u9ad4\u9a57\u4e26\u4fdd\u8b77\u60a8\u7684\u5de5\u4f5c\u3002<\/p>\n<p><a class=\"xiaomi\" href=\"https:\/\/allthings.how\/how-to-exit-vi-in-linux\/\" rel=\"noopener noreferrer nofollow\" target=\"_blank\">\u4f86\u6e90<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0d\u65bc Linux \u65b0\u624b\u4f86\u8aaa\uff0cvi\u7531\u65bc\u5176\u7368\u7279\u7684\u6a21\u5f0f\u548c\u547d\u4ee4\u7d50\u69cb\uff0c\u96e2\u958b\u7de8\u8f2f\u5668\u901a\u5e38\u6703\u611f\u5230\u56f0\u60d1\u3002\u7121\u8ad6\u60a8\u6253\u7b97\u4fdd\u5b58\u9032\u5ea6\u9084\u662f\u5b8c\u5168\u653e\u68c4\u66f4\u6539\uff0c\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u9000\u51fa\u90fd\u5f88\u91cd\u8981\u3002 \u4e0d\u540c\u7684\u6a21\u5f0fvi \u6b64vi\u7de8\u8f2f\u5668\u4e3b\u8981\u4ee5\u5169\u7a2e\u4e3b\u8981\u6a21\u5f0f\u904b\u4f5c\uff1a \u547d\u4ee4\u6a21\u5f0f\uff1a\u6b64\u6a21\u5f0f\u7528\u65bc\u5c0e\u822a\u548c\u57f7\u884c\u4e0d\u540c\u7684\u547d\u4ee4\u3002 \u63d2\u5165\u6a21\u5f0f\uff1a\u6b64\u6a21\u5f0f\u53ef\u8b93\u60a8\u65b0\u589e\u548c\u4fee\u6539\u6587\u5b57\u3002 \u7576\u60a8\u958b\u555f \u6642vi\uff0c\u5b83\u9810\u8a2d\u70ba\u547d\u4ee4\u6a21\u5f0f\u3002\u82e5\u8981\u5207\u63db\u5230\u63d2\u5165\u6a21\u5f0f\uff0c\u8acb\u6309i\u3002\u82e5\u8981\u5f9e\u63d2\u5165\u6a21\u5f0f\u8fd4\u56de\u547d\u4ee4\u6a21\u5f0f\uff0c\u53ea\u9700\u6309\u5373\u53efEsc\u3002 \u5982\u4f55\u5132\u5b58\u8b8a\u66f4\u4e26\u9000\u51favi \u9996\u5148\uff0c\u6309Esc\u9032\u5165\u547d\u4ee4\u6a21\u5f0f\u3002 \u7136\u5f8c\uff0c\u9375\u5165:wq\u4e26\u9ede\u64caEnter\u3002 \u6b64\u5e8f\u5217\u5c07\u4fdd\u5b58\u60a8\u7684\u4fee\u6539\u4e26\u95dc\u9589\u7de8\u8f2f\u5668\u3002 \u95dc\u9589vi\u800c\u4e0d\u5132\u5b58\u66f4\u6539 \u6309\u6b64\u9375Esc\u5207\u63db\u5230\u6307\u4ee4\u6a21\u5f0f\u3002 \u9375\u5165:q!\u4e26\u6309Enter\u3002 \u6b64\u65b9\u6cd5\u5c07\u9000\u51fa\uff0cvi\u800c\u4e0d\u4fdd\u7559\u6703\u8a71\u671f\u9593\u6240\u505a\u7684\u4efb\u4f55\u8b8a\u66f4\u3002 \u53e6\u4e00\u7a2e\u4fdd\u5b58\u4e26\u9000\u51fa\u7684\u65b9\u6cd5 \u6309 \u78ba\u8a8d\u60a8\u8655\u65bc\u547d\u4ee4\u6a21\u5f0fEsc\u3002 \u7136\u5f8c\uff0c\u8f38\u5165:x\u4e26\u6309Enter\u3002 \u53ea\u6709\u7576\u66f4\u6539\u5b58\u5728\u6642\uff0c\u8a72:x\u547d\u4ee4\u624d\u6703\u4fdd\u5b58\u9019\u4e9b\u66f4\u6539\uff0c\u7136\u5f8c\u9000\u51favi\u3002 vi\u4f7f\u7528\u5feb\u6377\u9375\u9000\u51fa \u6309Esc\u9032\u5165\u547d\u4ee4\u6a21\u5f0f\u3002 \u6309Shift+Z\u5169\u6b21 ( ZZ) \u5132\u5b58\u4e26\u9000\u51fa\u3002 \u4f7f\u7528ZZ\u5c07\u7acb\u5373\u5132\u5b58\u60a8\u7684\u8b8a\u66f4\u4e26\u95dc\u9589\u7de8\u8f2f\u5668\u3002 Esc\u5982\u679c\u9470\u5319\u5931\u9748\u600e\u9ebc\u8fa6 \u5982\u679cEsc\u6309\u9375\u4e0d\u8d77\u4f5c\u7528\uff0c\u8acb\u5617\u8a66\u4ee5\u4e0b\u66ff\u4ee3\u65b9\u6cd5\u4f86\u9032\u5165\u547d\u4ee4\u6a21\u5f0f\uff1a \u6309Ctrl+ [\u3002 \u6309Ctrl+ C\u3002 \u6210\u529f\u5207\u63db\u5230\u547d\u4ee4\u6a21\u5f0f\u5f8c\uff0c\u60a8\u53ef\u4ee5\u57f7\u884c\u5c0d\u61c9\u7684\u547d\u4ee4\u9000\u51favi\u3002 \u89e3\u6c7a\u5e38\u898b\u554f\u984c \u5982\u679c\u60a8\u5728\u5617\u8a66\u9000\u51fa\u6642\u9047\u5230\u932f\u8aa4\u8a0a\u606f\uff0c\u4f8b\u5982\uff1a E37: No write since last change (add! to override) \u9019\u8868\u793a\u9084\u6709\u5c1a\u672a\u5132\u5b58\u7684\u8b8a\u66f4\u3002\u82e5\u8981\u9000\u51fa\u4e0d\u5132\u5b58\uff0c\u8acb\u4f7f\u7528:q!.\u82e5\u8981\u5132\u5b58\u60a8\u7684\u5de5\u4f5c\u4e26\u9000\u51fa\uff0c\u8acb\u9078\u64c7:wq\u6216ZZ\u3002 \u719f\u6089\u6b63\u78ba\u7684\u9000\u51fa\u7a0b\u5e8fvi\u53ef\u4ee5\u589e\u5f37\u60a8\u7684\u6574\u9ad4\u9ad4\u9a57\u4e26\u4fdd\u8b77\u60a8\u7684\u5de5\u4f5c\u3002 \u4f86\u6e90<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[206,129],"class_list":["post-4944","post","type-post","status-publish","format-standard","hentry","category-how-to","tag-linux","tag-microsoft"],"acf":[],"_links":{"self":[{"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/posts\/4944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/comments?post=4944"}],"version-history":[{"count":1,"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/posts\/4944\/revisions"}],"predecessor-version":[{"id":4945,"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/posts\/4944\/revisions\/4945"}],"wp:attachment":[{"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/media?parent=4944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/categories?post=4944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/howtogeek.blog\/zh\/wp-json\/wp\/v2\/tags?post=4944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}