How to display line number in vim

How do I display line numbers in vim running on Linux or Unix-like operating systems?

Vim user need to type :set number command within vim text editor session when you are editing the file to display line number in vim. In this tutorial we will show you how to show line number in vim on Linux based desktop or server systems.

Start the vim editor

You need to start vim text editor. Open the terminal application and type:

How to display line number in vim

Simply type the following commands to display line number in the left margin:

  1. Press the ESC key
  2. At the : prompt type the following command to run on line numbers: set number
  3. To turn off line numbering, type the following command at the : prompt again: set nonumber

How to show line number in vim

To show line number along the left side of a vim window, type any one of the following command while using vim text editor. First press the Esc key. Press : and type any one of the following command at a : prompt –
set nu
Alternatively, type:
set number

How to make the vim editor display line number by default

If you need line number every time you start vim text editor, append the following line to your ~/.vimrc file:
vim ~/.vimrc
Append the following line:
set number
Save and close the file in vim.

Change gutter column width for numbering in vim

The vim syntax is:
:set numberwidth=2
Try the following in ~/.vimrc config file:
set numberwidth=2

Configure text wrapping for the number column in vim

Run the following syntax within vim:
:set cpoptions+=n
Or as usual add it to ~/.vimrc:
set cpoptions+=n


In this tutorial, you learned how to display line number in vim and permanently show line number in vim using $HOME/.vimrc file.

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.

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