How to display Line Numbers in Nano, Vi and VIM

Displaying line numbers in text editors like Nano, Vi, and Vim can be a crucial feature for developers, system administrators, and technical writers. These text editors are available on Linux. It aids in navigation and makes it easier to reference specific lines of code or text. Below is a detailed procedure for enabling line numbers in each of these text editors.


NANO

Displaying Line Numbers in Nano

  • Open the Nano Editor: Launch your terminal and type nano followed by the name of the file you wish to edit. For example:

Bash
nano example.txt

  • Access the Nano Menu: Once the editor is open, you’ll notice a menu at the bottom of the screen. This menu contains various commands prefixed by the caret symbol (^), which represents the Ctrl key.
  • Enable Line Numbers: To display line numbers, press Alt + Shift + #. This will toggle line numbers on or off.
  • Save Changes: To save any changes you’ve made to the file, press Ctrl + O, then press Enter.
  • Exit Nano: To exit the Nano editor, press Ctrl + X.

Top Tip for Nano

Did you know you can quickly view which line you are on in Nano by pressing CRTL+C anywhere in your file? For example:

Want to make setlinenumbers persistent?

1.Edit .nanorc

You can use Nano itself to edit this configuration file. Open your terminal and type:

Bash
nano ~/.nanorc 

This will open the nanorc file in your home directory (represented by ~). If the file doesn’t exist, Nano will create it for you.

2. Add the line:

In the Nano editor, add the following line:

Bash
set linenumbers


VI

Displaying Line Numbers in Vi

  • Open the Vi Editor: In your terminal, type vi followed by the name of the file you want to edit. For instance:

Bash
vi example.txt

  • Enter Command Mode: By default, Vi starts in “Normal” mode. To enter “Command” mode, press Esc.
  • Enable Line Numbers: In “Command” mode, type :set number and press Enter. This will display line numbers along the left-hand side of the editor.
  • Save and Exit: To save changes and exit Vi, type :wq and press Enter.


VIM

Displaying Line Numbers in Vim

  • Launch Vim: Open your terminal and type vim followed by the name of the file you wish to edit. For example:

Bash
vim example.txt

  • Switch to Command Mode: Vim starts in “Normal” mode. Press Esc to switch to “Command” mode.
  • Activate Line Numbers: In “Command” mode, type :set number and press Enter. This will enable line numbers.
  • Persistent Line Numbers: If you want to make this setting permanent, you can add the set number command to your Vim configuration file. To do this, open your .vimrc file by typing vim ~/.vimrc and add the line set number.
  • Save and Close: To save your changes and exit Vim, type :wq and press Enter.

Thanks for taking the time to read this article. if you have any questions or feedback, please write in the comment section below.

Elsewhere On TurboGeek:  EXT4 Data Recovery For Linux File System Experts

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate ยป