In the vi editor, which command is used to save the current file without quitting, thereby remaining in the editing mode?
Computer Science
Linux
Difficulty: Easy
Choose an option
-
Ax
-
Bq!
-
C:w
-
D:q
-
ENone of the above
Answer
Correct Answer: :w
Explanation
Introduction / Context:The vi editor in Unix/Linux is one of the most powerful text editors. A core skill is knowing how to save changes without exiting the editor. This helps when you want to preserve your work but continue editing further.
Given Data / Assumptions:
- User is working in vi editor.
- Requirement is to save changes but remain in editing mode.
Concept / Approach:
Commands in vi begin with a colon (:) when in command mode. The :w command writes (saves) the file to disk but does not close it, allowing the user to continue editing.
Step-by-Step Solution:
Open vi with vi filename.txt.Make changes in insert mode, then press ESC to return to command mode.Type :w and press Enter.The editor reports “filename written” and remains open for editing.Verification / Alternative check:
Compare :wq which saves and quits. Using only :w leaves you in vi to continue editing.
Why Other Options Are Wrong:
- x: writes and exits.
- q!: quits without saving.
- :q: quits only if no changes are made.
- None of the above: incorrect because :w is correct.
Common Pitfalls:
- Forgetting to press ESC before entering command mode.
- Confusing :w with :wq.
Final Answer:
:w.