How to Show Line Number in vi or vim Editor

A VI or VIM editor is a simple editor used by system administrators or programmers in Linux and Unix server environment. vi or vim is actually the same thing as is has same usage and same purpose. Vim is a text editor that is upwards compatible to Vi. Both can be used to edit all kinds of plain text and programs. By default, Vi and vim does not show the line number and this is very inefficient. However, there is the step to show line number in vi or vim editor. Follow this example:

1. Select any file to view in vi editor. For example httpd.conf

    [root@server ~]# vi /etc/httpd/conf/httpd.conf
    
    #
    # This is the main Apache server configuration file.  It contains the
    # configuration directives that give the server its instructions.
    # See  for detailed information.
    # In particular, see
    #
    # for a discussion of each configuration directive.
    #
    #
    # Do NOT simply read the instructions in here without understanding
    # what they do.  They're here only as hints or reminders.  If you are unsure
    # consult the online docs. You have been warned.
    #
    # The configuration directives are grouped into three basic sections:
    #  1. Directives that control the operation of the Apache server process as a
    #     whole (the 'global environment').
    #  2. Directives that define the parameters of the 'main' or 'default' server,
    #     which responds to requests that aren't handled by a virtual host.
    #     These directives also provide default values for the settings
    #     of all virtual hosts.
    #  3. Settings for virtual hosts, which allow Web requests to be sent to
    #     different IP addresses or hostnames and have them handled by the
    #     same Apache server process.
    

2. Once you are in vi or vim editor, makesure you press ESC.
3. In vi or vim editor type the command below:-

    :set number
    

or

    :set nu
    

Once entered, you will see the line number showing at the left side.

          1 #
          2 # This is the main Apache server configuration file.  It contains the
          3 # configuration directives that give the server its instructions.
          4 # See  for detailed information.
          5 # In particular, see
          6 #
          7 # for a discussion of each configuration directive.
          8 #
          9 #
         10 # Do NOT simply read the instructions in here without understanding
         11 # what they do.  They're here only as hints or reminders.  If you are unsure
         12 # consult the online docs. You have been warned.
         13 #
         14 # The configuration directives are grouped into three basic sections:
         15 #  1. Directives that control the operation of the Apache server process as a
         16 #     whole (the 'global environment').
         17 #  2. Directives that define the parameters of the 'main' or 'default' server        ,
         18 #     which responds to requests that aren't handled by a virtual host.
         19 #     These directives also provide default values for the settings
         20 #     of all virtual hosts.
         21 #  3. Settings for virtual hosts, which allow Web requests to be sent to
         22 #     different IP addresses or hostnames and have them handled by the
    

4. If you want to hide the line number, you can use the command below:-

    :set nonumber
    

or

    :set nonu
    

How to Reset the Directory Manager Password on RHEL 7 / CentOS 7
How to Reset the Directory Manager Password on RHEL 7 / CentOS 7

It is best practice to remember passwords, but because too many passwords, sometimes we forget. We are not encouraged to write the password on any paper or share the password...

How to Find Big Files Size on Linux RHEL/CentOS
How to Find Big Files Size on Linux RHEL/CentOS

As the linux administrator, sometimes we have to identify which files are most take much space in the linux server resulting in low free space. Low disk space can also...

Why Linux users should worry about malware and what they can do about it
Why Linux users should worry about malware and what they can do about it

Don’t drop your guard just because you’re running Linux. Preventing the spread of malware and/or dealing with the consequences of infection are a fact of life when using computers. If...

How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7
How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7

This short howto will explain the steps to reset a lost root password or to reset a forgotten root password on Linux RHEL 7 or CentOS 7. Basically, we will...

How to Update CentOS or Upgrade CentOS to the Latest Version
How to Update CentOS or Upgrade CentOS to the Latest Version

Recently, the latest version of CentOS 7.3 was released. All users of CentOS 7.0, 7.1 and 7.2 can upgrade their system to the most recent. This quick guide will explain...

How to Change your WordPress Username, Nickname and Display Name in MySQL
How to Change your WordPress Username, Nickname and Display Name in MySQL

After you create an account log in WordPress, you may want to change your WordPress username, as appropriate or due to security reason. However, you can not do this from...

How to Enable SSH Root Login on Ubuntu 16.04
How to Enable SSH Root Login on Ubuntu 16.04

As what we wrote in the previous article on how to allow SSH root on Ubuntu 14.04, after installing a fresh new copy of Ubuntu 16.04 LTS, we find that...

How to Change UUID of Linux Partition on CentOS 7
How to Change UUID of Linux Partition on CentOS 7

UUID (Universally Unique IDentifier) should be unique and it is used to identify storage devices on a linux system. If you cloned a virtual machine from vCenter, the metadata containing...

Leave a Reply

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