Difficulty: Easy
Correct Answer: :w
Explanation:
Introduction / Context:
Efficient editing in UNIX/Linux often relies on the vi editor (and its enhanced successor, Vim). Knowing the difference between save-only and save-and-quit commands is essential to prevent accidental exits and to preserve work frequently during long edit sessions.
Given Data / Assumptions:
Concept / Approach:
Colon commands in vi provide file-level and session-level actions. The command :w writes the current buffer to the associated filename. Commands like :x and :wq both write and exit, while :q attempts to quit and :q! forces quit without saving. Therefore, the save-only action corresponds to :w.
Step-by-Step Solution:
Verification / Alternative check:
Use :ls or :buffers in Vim to confirm buffer state, and check timestamps with ls -l from a shell to ensure the write occurred. Reopen the file to confirm your recent changes persist.
Why Other Options Are Wrong:
a: :q attempts to quit; it does not save, and it exits if there are no unsaved changes.
c: q! forces quit without saving—dangerous if you intend to keep edits.
d: :x writes and quits (similar to :wq), not save-only.
e: Not applicable because :w is the correct save-and-stay command.
Common Pitfalls:
Mistyping :wq instead of :w, which will exit unintentionally; forgetting to write with elevated privileges when editing protected files (use :w !sudo tee % in Vim); confusing uppercase Q (ex mode) with :q.
Final Answer:
:w
Discussion & Comments