Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between wq and x in vi

Tags:

vi

save

quit

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?

like image 945
Mohammed H Avatar asked Dec 12 '12 16:12

Mohammed H


People also ask

What is difference between X and WQ?

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.

What does WQ do in vi?

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.

What is the difference between WQ and WQ in vi editor?

: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.

What is the meaning WQ in Vim?

: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.


1 Answers

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.
like image 189
bua Avatar answered Sep 30 '22 18:09

bua