How to Set Line Numbers in Vim

How do I set line numbers in vim permanently?

You can show how to display or hide line numbers in Vim text editor using set number command.

Showing absolute line numbers in vim

  1. To get the standard line numbering open your file in vim:
    vim filename
  2. Next press the Esc key to switch to command mode in vim.
  3. Press : (colon) and and type set number or set nu and hit the Enter key. For example:
    :set number
    :set nu
    Screenshot from 2023-01-21 01-42-01
  4. Line numbers will be displayed at the left side of the vim editor.
  5. To disable the absolute line numbers off type the following command. Press the Esc key and type:
    :set nonumber

In short, to show line numbers in Vim text editor, use the :set number command for absolute line numbers, :set relativenumber for relative line numbers. For more info see the following: