I always using :wq
to save a file. Today, I came to know that :x
can be used to do that. But I didn't notice it in any vi-tutorial or vi-quick-reference. Is there any difference between these two commands?
The difference between those twos is very simple: :x saves changes to the file only it it has been modified, while :wq changes the modification time no matter what.
Press Esc to enter Command mode, and then type :wq to write and quit the file. The other, quicker option is to use the keyboard shortcut ZZ to write and quit. In Vi, write means save, and quit means exit.
: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.
:w - Saves the file you are working on. :w [filename] - Allows you to save your file with the name you've defined. :wq - Save your file and close Vim. :q! - Quit without first saving the file you were working on.
From
help :x
*:x* *:xit*
:[range]x[it][!] [++opt] [file]
Like ":wq", but write only when changes have been
made.
When 'hidden' is set and there are more windows, the
current buffer becomes hidden, after writing the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With