Linux view and edit files

vi editing method

  Open the terminal, enter vi test.txt and press Enter, press a or i to enter the editing mode, enter I am a boy, and then press the esc key to exit the editing mode, enter: wq to save and exit.

  1. VIM editor, you can create new files or modify files, the command is: vim /usr/local/con.cfg
  2. If this file does not exist before, it is a new file, and there is a prompt below as a new file, if the file already exists, there is no prompt.
  3. After entering the editor, we first press "I" to switch to the "insert" state. You can edit the content by moving the cursor up, down, left, and right, or space, backspace, and enter, which is the same as WINDOWS.
  4. When the text editing is over, you usually need to exit the editor. Exit the editor is divided into 4 situations: save and exit, normal exit, exit without saving and forced exit. 
  5.  Press "ESC" in the upper left corner of the keyboard, the insert state in the lower left corner is gone
  6. Then at this time, we enter the "colon", that is, ":" (without double quotation marks), a colon will appear below, waiting for the input command, as shown in the figure, I entered WQ. The functions are as follows.
    W: write, write
    Q: quit, exit
    and press enter, save and exit
  7. In fact, there are two ways to save and exit:
    A: When entering the command at the end, directly enter "x", which is the same, that is, X=WQ.
    B: The quickest way: After pressing ESC, directly press shift+zz, or switch to uppercase mode and press ZZ to save and exit, that is, press uppercase Z twice.
  8. You can use the view command: cat to view its content: cat /usr/local/con.cfg
  9. A prerequisite for normal exit is that the content of the opened text file has not been changed.
    After pressing ESC, enter a colon. When entering a command, enter "q" directly,
  10. The way to exit without saving. Many times when you open the file or modify some places, you find that it is wrong. It is very necessary to exit without saving.

    Press ESC first, then enter a colon, when entering a command, directly enter "q!"

  11. Force exit. This is really something you shouldn't do, because it's so fucking!

    Press ESC first, then press the colon, when inputting a command, directly input "!"

Guess you like

Origin blog.csdn.net/qq_39331713/article/details/98754670