Got it

Linux ESC: The difference between :wq and :wq!

Latest reply: Sep 24, 2021 08:29:22 8511 7 9 0 0

Hi, Community!

This article describes the difference between :wq and :wq!


How to use the :wq/:wq! command

1. Use cd command to enter the path of the object file.

2. Use vi object file to edit the file.

3. The vi has three mode: Command mode, Insert mode, and Last line mode.

  • Command mode: When you start vi, you enter command mode. The keystroke action in this state is recognized by Vim as a command, not as an input character.

    • i: Switch to insert mode.

    • x: Deletes the character where the current cursor is located.

    • : : Toggles the last line mode to enter commands on the bottom line

  • Insert mode

  • Last line mode:

    • q: Exit the program.

    • w: Save the file.

    • ESC: exit the Last line mode.

4. Enter i to enter the insert mode.

5. Edit the file.

6. Enter : to enter last line mode, and enter wq/wq! to save and exit.

The difference between :wq and :wq!

:Wq (Save edit operation and exit): Writing even if the file has not been modified, and updates the modification time of the file.

:Wq! (Save edit and force exit): Mandatory write to file and forced exit, ! for enforcement.

Some files are set to read-only. Generally, they are not modified. However, if you are the owner or root of the file, you can run :wq! to save the file and exit the file. If you do not have permission on the file, it does not force a write.

 

The difference between :wq and :x

:x Write to the file and exit. Write only when the file is modified, and update the file modification time; otherwise, the file modification time will not be updated.

 

Both :wq and :x are generally the same, but in terms of programming, there may be a significant impact on editing source files. Because the file is not modified, ":wq" forces the update time of the file to be updated. This will cause make to compile the entire project, thinking that the file has been modified, and then recompile the link to generate the executable. This can have misleading consequences and, of course, unnecessary system resource costs. Therefore, we have to get used to :x to save resources.


The difference between :q and :q!

:q in vim indicates that the user exits. :q! indicates that the file is not saved and exits forcibly.

The differences between :q and :q!" are as follows:


  • If the file is modified, the :q prompts you whether to exit. Enter y to exit.

  • If the file is modified, run the :q! command. will force a direct exit, and the file will not be retained.

Thanks!

Thank you for this excellent sharing! The difference between wq and wq!
View more
  • x
  • convention:

After it, you can know the wq, wq!, x.
Linux ESC: The difference between :wq and :wq!-3847543-1
View more
  • x
  • convention:

GOOD
View more
  • x
  • convention:

I usually use wq: in linux
View more
  • x
  • convention:

informative
View more
  • x
  • convention:

Good share
View more
  • x
  • convention:

Y_T_Z
Y_T_Z Created Jan 7, 2022 08:00:25 (0) (0)
Thanks!
This command is used very frequently.  

Comment

You need to log in to comment to the post Login | Register
Comment

Notice: To protect the legitimate rights and interests of you, the community, and third parties, do not release content that may bring legal risks to all parties, including but are not limited to the following:
  • Politically sensitive content
  • Content concerning pornography, gambling, and drug abuse
  • Content that may disclose or infringe upon others ' commercial secrets, intellectual properties, including trade marks, copyrights, and patents, and personal privacy
Do not share your account and password with others. All operations performed using your account will be regarded as your own actions and all consequences arising therefrom will be borne by you. For details, see " User Agreement."

My Followers

Login and enjoy all the member benefits

Login

Block
Are you sure to block this user?
Users on your blacklist cannot comment on your post,cannot mention you, cannot send you private messages.
Reminder
Please bind your phone number to obtain invitation bonus.