How do I show lines in vi or vim text editor?

I am using a Linux based system. In, vi or vim text editor, how do I show or hide line numbers? How do I show lines in vi?

Introduction: One can make the vi or vim text editor display or hide line numbers using set number command. This page shows how to make the vi editor show or hide line numbers when using under Linux or Unix-like systems.

How to show lines in vi or vim text editor

To force vim or vi text editor display line numbers

  1. Press the ESC key
  2. Type : (the colon)
  3. Execute the following command to show lines in vi/vim:
    set number
  4. Now you can see line numbers on the left side of the vi/vim text editor screen

How to hide lines in vi or vim text editor

  1. Press the ESC key
  2. Type : (the colon)
  3. Execute the following command to hide lines in vi/vim:
    set nonumber

How do I make line number vi / vim editor settings permanent?

Usually, your vi or vim editor forget the setting as soon as you left the editor. You can make the setting take effect automatically whenever you use vi. To do this, edit a file named ~/.exrc for vi text editor and ~/.vimrc for vim text editor.

How to show line numbers in the vim editor automatically

You need to edit your personal Vim/vi text editor initializations and config file. The file located at $HOME/.vimrc or ~/.vimrc. To change default settings of Vim/vi editor such as setting up line number, run:
vi ~/.vimrc
OR
vi $HOME/.vimrc
Append the following line:

set number

However, one can only display line number on files with py (Python) extension:

autocmd BufReadPost *.py set number

Save and close the file.

Conclusion

You learned how to set, hide/display line number in VI or Vim text editor running on a Linux, macOS or Unix-like operating systems.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Total
0
Shares
Leave a Reply

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

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts