Detailed Explanation of VIM Exit Command [Edit Exit Command]

   vim starts vim directly

   vim filename opens a file (creates a file named filename if it does not exist)

If we need to enter information, we can press the keyboard i, and we can see that the mode below becomes: INSERT

After entering the content information you want, press ESC to switch modes.

Vim is an editor that distinguishes between editing modes , divided into three editing modes:

1. Normal mode/Normal mode (press Esc or Ctrl+[ to enter) The lower left corner displays the file name or is empty:

Quit Vim commands ZZ and ZQ

ZZ: Exit Vim; if the file is modified, save the file first and then exit. Programmers must remember the common commands. (equivalent to the :x command)

ZQ: Force quit Vim without saving any changes. Use it carefully, otherwise the words you type may disappear in a while. It was a waste of time. (equivalent to the :q! command),


2. Edit mode/insert mode (press i key to enter) --INSERT-- is displayed in the lower left corner:

1) Enter the vim file name . This opens a file.

2) Press the keyboard i to enter the editing mode.

  1. i Insert before the current position
  2. I Insert at the beginning of the current line
  3. a is inserted after the current position
  4. A Insert at the end of the current line
  5. o Insert a row after the current row
  6. O Insert a row before the current row

3) Enter the content information you want, and then press the esc key to switch modes at this time

4) Enter :wq directly , which means to save after writing.

Or: press ctrl+z to exit

3. Command line mode/visual mode (I don’t know how to enter) The lower left corner displays --VISUAL--:

        1) Exit Vim directly

:q Exit the current Vim window, or exit Vim (or :quit) if the current window is the last window.

:conf q Quit the current Vim window, if the current window has been modified, it will give a prompt to make a choice (or :confirm quit).

:q! Force quit the current Vim window and ignore all changes, even if the current buffer has been modified without saving (or :quit!:).

:cq Quit Vim without saving the file in any case, and return an error code (or :cquit:).

:qa Quit all Vim windows unless a modified buffer exists (or :qall:).

:conf qa Quit all open Vim windows; if there are modified buffers, give a prompt to choose (or :confirm qall: ).

:qa! Force quit all open Vim windows without saving any changes (or :qall! :)

:e! Discard all changes and open the original file.

        2) Save the file and exit Vim

:wq: Save and exit. Save the current file and exit Vim. The writeback operation will fail if the file is read-only or if the buffer is unnamed.

:wq test.txt: Save the contents of the current Vim buffer to the file test.txt and exit Vim.

:[range]wq test.txt: Save the content defined by range in the current Vim buffer to the file test.txt and exit Vim.

:[range]x test.txt: The function is similar to :[range]wq test.txt, but only when the file is modified, it will be actually saved.

Guess you like

Origin blog.csdn.net/Moonlight_16/article/details/120022203