日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

如何退出Vi或Vim编辑器

發布時間:2024/3/12 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何退出Vi或Vim编辑器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

The vi editor is confusing if you’re not used to it. It takes a secret handshake to escape this application if you’ve stumbled into it. Here’s how to quit vi or vim on Linux, macOS, or any other Unix-like system.

如果您不習慣使用vi編輯器,則會感到困惑。 如果您偶然發現該應用程序,則需要進行一次秘密握手才能退出該應用程序。 這是在Linux,macOS或任何其他類似Unix的系統上退出vi或vim的方法。

快速解答 (The Quick Answer)

If you’re in vi or vim and need to get out—with or without saving your changes—here’s how:

如果您使用的是vi或vim ,需要保存或不保存所做的更改,那么請按照以下步驟操作:

  • First, press the Esc key a few times. This will ensure vi is out of Insert mode and in Command mode.

    首先,按幾次Esc鍵。 這將確保vi退出插入模式和命令模式。

  • Second, type :q! and press Enter. This tells vi to quit without saving any changes. (If you do want to save your changes, type :wq instead.)

    其次,輸入:q! 然后按Enter。 這告訴vi退出而不保存任何更改。 (如果確實要保存更改,請鍵入:wq 。)

If you want to learn the Linux command line, you’ll need to know a lot more than that. Read on and we’ll show you just how vi works and why the instructions for quitting are so unusual. vi is an important, powerful tool and the learning curve is worth it.

如果您想學習Linux命令行,則需要了解更多。 繼續閱讀,我們將向您展示vi工作原理以及為什么退出說明如此不尋常。 vi是一個重要而強大的工具,學習曲線值得。

vi,無所不在的編輯器 (vi, The Ubiquitous Editor)

Because vi is everywhere the chances are you’re going to run up against it. You can even find yourself inside vi by accident. Perhaps someone asks you to look at their Linux computer for them. You issue a command like crontab -e , and vi pops up. Surprise, someone has configured the default editor for crontab?to be vi.

因為vi無處不在,所以您將有機會與之抗衡。 您甚至可能偶然發現自己在vi 。 也許有人要您為他們看一下他們的Linux計算機。 您發出諸如crontab -e類的命令,然后vi彈出。 令人驚訝的是,有人將crontab的默認編輯器配置為 vi 。

Perhaps you’re administering a system where vi is the only editor, or the only one that will work through a remote SSH session, and you need to edit a user’s .bashrc file.

也許您正在管理一個系統,其中vi是唯一的編輯器,或者是唯一將通過遠程SSH會話運行的編輯器,并且您需要編輯用戶的.bashrc文件。

The command to start vi and open a file is straight forward. Type vi , a space, and then the filename. Press Enter. The program that is launched might be vi or it might be vim , an ‘improved vi‘. It depends on your Linux distribution—for example, Ubuntu uses vim . All of the instructions in this article apply equally to vim.

啟動vi和打開文件的命令很簡單。 鍵入vi ,一個空格,然后輸入文件名。 按Enter鍵。 啟動的程序可能是vi ,也可能是vim ,即“改進的vi ”。 這取決于您的Linux發行版-例如,Ubuntu使用vim 。 本文中的所有說明同樣適用于vim 。

vi .bashrc

The immediately noticeable difference between vi and other editors is that when vi launches you can’t just start typing text. That’s because vi?is a modal editor. Editing is performed in one mode, the Insert mode, and issuing commands is performed in the Command mode.?vi launches into Command mode.

vi和其他編輯器之間最明顯的區別是,在啟動vi您不能只是開始輸入文本。 這是因為vi是模式編輯器。 編輯是在一種模式(插入模式)下執行的,發出命令是在命令模式下執行的。 vi進入命令模式。

If you’re unfamiliar with the concept of Insert mode and Command mode, it can be baffling. A great many of the commands that you can issue in Command mode affect the file you’re typing. If you are in Command mode but you’re mistakenly trying to type text into your file, it isn’t going to end well. Some of the keystrokes you issue will be recognized as commands. Those commands are liable to delete or split lines, move the cursor around, or delete text.

如果您不熟悉插入模式和命令模式的概念,可能會感到困惑。 您可以在“命令”模式下發出的許多命令都會影響您正在鍵入的文件。 如果您處于“命令”模式,但是錯誤地嘗試在文件中鍵入文本,則結尾將不會很好。 您發出的某些按鍵將被識別為命令。 這些命令可能會刪除或分割行,四處移動光標或刪除文本。

And, no matter what you type, you can’t find a way to exit or quit from the editor. Meanwhile, your file is getting pretty mangled and the seemingly random beeps are driving you crazy.

而且,無論您鍵入什么內容,都找不到退出編輯器的方法。 同時,您的文件變得非?;靵y,看似隨機的嗶嗶聲使您發瘋。

命令模式和插入模式 (Command Mode and Insert Mode)

You need to switch?vi into the appropriate mode for what you’re trying to accomplish.

您需要將vi切換到要完成的任務的適當模式。

Command mode is the default mode when vi launches. Unless you know better, you’ll start trying to type. If you happen to hit the ‘i’ key, or any of the other 10 keys that invoke Insert mode (a, A, c, C, I, o, O, R, s, and S) you’ll suddenly see what you’re typing. You’re now in Insert mode.

vi啟動時,命令模式是默認模式。 除非您對此有所了解,否則將開始嘗試輸入。 如果碰巧按下“ i”鍵或調用插入模式的其他10個鍵(a,A,c,C,I,o,O,R,s和S)中的任何一個,您會突然看到您正在輸入。 您現在處于插入模式。

This might feel like progress until you hit one of the arrow keys. If you do that, A, B, C, or D will appear as the only letter on an otherwise blank new line. At the top of the file.

直到您按下其中一個箭頭鍵,這似乎才是進步。 如果這樣做,則A,B,C或D將作為唯一字母出現在否則為空白的新行上。 在文件的頂部。

It’s OK, we’ve got your back. This is surprisingly easy when you know how. Remember these two keystrokes: Esc takes you to Command mode and “i” takes you to Insert mode.

沒關系,我們得到了您的支持。 當您知道如何時,這非常容易。 記住這兩個按鍵:Esc帶您進入命令模式,“ i”帶您進入插入模式。

You need to be in Command mode, and to enter the correct command to leave the editor.

您需要處于“命令”模式,并輸入正確的命令才能離開編輯器。

從命令模式到安全 (From Command Mode to Safety)

To enter Command mode, hit the Esc key. Nothing visible will happen. Hit it a few more times. If you hear a beep when you hit the Escape key, then you’re in Command mode. The beep is telling you “Stop pressing Esc, you’re in Command mode, already.” If you hear a beep when you hit Esc, we’re good.

要進入命令模式,請按Esc鍵。 什么都看不見。 再打幾次。 如果在按Escape鍵時聽到蜂鳴聲,則說明您處于命令模式。 嗶聲告訴您“停止按Esc鍵,您已經處于Command模式?!?如果您在按Esc鍵時聽到嗶嗶聲,那就很好。

Type a colon, the letter “q,” and an exclamation point, without any spaces. These three characters should appear at the far left of the bottom line of the terminal. If they don’t, hit Esc until you hear a beep, and try again. Press the Enter key when you can see them:

鍵入一個冒號,字母“ q”和一個感嘆號,沒有任何空格。 這三個字符應顯示在終端的底行的最左端。 如果不是,請按Esc,直到聽到提示音,然后重試。 看到它們時,按Enter鍵:

:q!

In this command q is an abbreviation for quit . The exclamation point adds emphasis, so it’s like you’re shouting “Quit!” at vi. That might make you feel a little better.

在此命令中q是quit的縮寫。 感嘆號增加了重點,就像您在喊“退出!” 在vi 。 那可能會使您感覺好一些。

The exclamation point also instructs vi to not save any of the changes you may have made to the file. If you’ve been blundering about in vi and not knowing what you’re doing you probably don’t want to save the havoc you’ve wreaked.

感嘆號還指示vi 不要保存您可能對該文件所做的任何更改。 如果您在vi一直犯錯誤而又不知道自己在做什么,則可能不想保存您造成的破壞。

Once you’re back at the command line you might want to double-check to make sure the file hasn’t been altered. You can do this with the following command:

返回命令行后,您可能需要仔細檢查以確保文件沒有被更改。 您可以使用以下命令執行此操作:

cat .bashrc | less

When you are exiting vi, if you see a message saying “no write since last change,” it means you missed the exclamation point off the command. To prevent you quitting and losing any changes you might wish to keep, vi is giving you the chance to save them. Just reissue the :q! command with the exclamation point in place to exit from vi and abandon any changes.

退出vi ,如果看到“自從上次更改以來沒有寫過”的消息,則表示您錯過了命令的感嘆號。 為了防止您退出并丟失希望保留的任何更改, vi提供了保存更改的機會。 只需重新發出:q! 帶有感嘆號的命令退出vi并放棄任何更改。

如果確定,請保存更改 (If You’re Sure, Save Your Changes)

If you’re happy with the changes you’ve made to your file, you can exit and save the changes using the :wq (write and quit) command. Make sure you are entirely satisfied that you want your screen edits written to the file before you proceed.

如果對文件所做的更改感到滿意,則可以使用:wq (寫入并退出)命令退出并保存更改。 在繼續操作之前,請確保您完全希望將屏幕編輯寫入文件。

Type a colon, the letter w (write) and the letter q (quit). Press the Enter key when you can see them in the lower left of the terminal:

輸入冒號,字母w(寫)和字母q(退出)。 當您在終端的左下方看到它們時,請按Enter鍵:

:wq

學習曲線值得 (The Learning Curve is Worth It)

Using vi is a bit like using a piano. You can’t just sit down and use it; you’ve got to put in some practice. Sitting down to it cold and trying to learn on the fly when the pressure is on you to get something edited is not the way to do it. It makes as much sense as sitting down to a piano for the first time just as the curtain raises for your inaugural concert.

使用vi有點像使用鋼琴。 您不能只是坐下來使用它; 您必須進行一些練習。 坐在冷的地方,試圖在壓力下立即學習以進行編輯,這并不是解決問題的方法。 這就像第一次坐鋼琴一樣有意義,就像為您的就職音樂會拉開帷幕一樣。

Much of the power of vi comes from its many keystroke combinations that each perform a common editing task. That’s great, but you can’t benefit from them until you have memorized them, practiced them, and they’re part of your muscle memory.

vi的強大功能主要來自于許多擊鍵組合,每個組合都執行共同的編輯任務。 太好了,但是只有記住,練習它們并且它們是您肌肉記憶的一部分,您才能從中受益。

Until then, if you find yourself in vi and looking at an important file, just :q! and exit gracefully. Your important file will thank you.

在此之前,如果您發現自己在vi查看重要文件,請:q! 然后優雅地退出。 您的重要文件將感謝您。

翻譯自: https://www.howtogeek.com/411210/how-to-exit-the-vi-or-vim-editor/

總結

以上是生活随笔為你收集整理的如何退出Vi或Vim编辑器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。