Which command is used with vi editor to save file and remain in the editing mode? A. :q B. :w C. q! D. :x E. None of the above

:q
:w
q!
😡 E. None of the above

The correct answer is: A. :q

The :q command saves the current file and exits the vi editor. If you have made changes to the file that have not been saved, you will be prompted to save them before exiting.

The :w command saves the current file without exiting the vi editor.

The q! command quits the vi editor without saving the current file.

The :x command is equivalent to :wq. It saves the current file and exits the vi editor.


Here is a brief explanation of each option:

  • A. :q

The :q command saves the current file and exits the vi editor. If you have made changes to the file that have not been saved, you will be prompted to save them before exiting.

For example, if you are editing a file called foo.txt, and you type :q, you will see the following message:

“`
No write since last change

[ynq] ?
“`

The y option means “yes, save the file and exit the editor.” The n option means “no, do not save the file and exit the editor.” The q option means “quit the editor without saving the file.”

If you type y, the file will be saved and the editor will exit. If you type n, the editor will exit without saving the file. If you type q, the editor will quit without saving the file and you will lose any changes you have made since the last time you saved the file.

  • B. :w

The :w command saves the current file without exiting the vi editor.

For example, if you are editing a file called foo.txt, and you type :w, the file will be saved and the editor will remain in the editing mode.

  • C. q!

The q! command quits the vi editor without saving the current file.

For example, if you are editing a file called foo.txt, and you type q!, the editor will quit without saving the file. If you have made changes to the file that have not been saved, you will lose those changes.

  • D. 😡

The :x command is equivalent to :wq. It saves the current file and exits the vi editor.

For example, if you are editing a file called foo.txt, and you type :x, the file will be saved and the editor will exit.

  • E. None of the above

The option E is not a valid vi command.

Exit mobile version