UNIX vi editor: Which :set option enables on-screen line numbers for every line while editing (for example, to assist with navigation and referencing specific lines)?

Difficulty: Easy

Correct Answer: nu

Explanation:


Introduction / Context:
When working in the UNIX vi editor, it is often helpful to display line numbers beside each line of text. This aids navigation, error reporting, and collaboration because commands like “:42” or “:1,10” become clearer when you can see the exact line indices. The vi/vim configuration uses the :set command to toggle editor options such as numbering, case sensitivity, and more.


Given Data / Assumptions:

  • You are editing a file in vi (or vim in vi-compatibility mode).
  • You want persistent line numbers in the display area (not just in status messages).
  • The question asks for the short option keyword used with :set.


Concept / Approach:
In classic vi, line numbers are enabled with the option named “number”. The short mnemonic for that option is “nu”. You can toggle it by entering command-line mode and typing :set nu to turn it on or :set nonu to turn it off. Vim additionally supports relative numbering (:set relativenumber), but the base, most universal option remains :set number (or :set nu).


Step-by-Step Solution:

Enter command-line mode by pressing colon.Type “set nu” and press Enter to enable line numbers.Verify that each screen line now shows a numeric index to the left of the text area.Optionally disable numbering with “:set nonu” if you no longer need it.


Verification / Alternative check:
Use :set number to see the same effect using the full option name. Run :set? number to query the current state; vi/vim reports whether the option is set or not.


Why Other Options Are Wrong:
nm: not a valid vi option for numbering. ic: stands for “ignorecase” in searches, unrelated to numbering. li: not the standard numbering option. None of the above: incorrect because “nu” is correct.


Common Pitfalls:
Confusing “nu” with “relativenumber” in vim; forgetting to prefix with colon in command-line mode; expecting numbering without issuing :set or editing ~/.vimrc to enable it permanently.


Final Answer:
nu

More Questions from Unix

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion