Published: July 22, 2026
Read: 8 min
In: Technology & Development

Written by

Reviewed by

Last updated: July 2, 2023

Expert verified

SVG Image

TL;DR

To show line numbers in Vim, you can try these methods:

  1. Configuring Vimrc Settings: Add set number to your Vimrc file to enable line numbers permanently.
  2. vim-airline Plugin: Install vim-airline, and line numbers will be displayed on the status bar.
  3. Activating Relative Line Numbers: Enter :set relativenumber to activate relative line numbers.

When showing line numbers in Vim, common errors may include invisible line numbers, out-of-sync numbering, overlapping with text, misalignment with the cursor, and performance slowdowns. To resolve these issues, check configuration settings, use relative line numbering, adjust fonts and spacing, address conflicts, and optimize Vim’s performance.

Continue reading the guide below to learn to show line numbers in Vim and common errors with possible solutions.

Line numbers are an essential feature in Vim that greatly enhances productivity and facilitates navigation within the editor. Line numbers serve as essential markers within your code, enabling you to locate and refer to specific lines quickly. By incorporating line numbers into your Vim workflow, you’ll experience enhanced code navigation, collaboration, and productivity. In this comprehensive guide, I will explore various methods to show line numbers in Vim and common errors that can occur when displaying line numbers in Vim.

How to Show Line Numbers in Vim

To show line numbers in Vim, you can configure your Vimrc settings to enable them by default, install the vim-airline plugin for visually appealing line numbers in the status bar, or activate relative line numbers for dynamic navigation based on line positions.

1. Configuring Vimrc Settings

If you prefer to have line numbers displayed by default whenever you open Vim, you can configure your Vimrc settings. This method ensures line numbers persist across multiple Vim sessions and provides a seamless experience for regular Vim users. To enable line numbers permanently, follow these steps:

  1. Launch your Terminal.
opening terminal 14
  1. Enter the following command to open your Vimrc file: 

<strong>vim ~/.vimrc </strong>
  1. The command will open vim configuration file.

opening-vim-configuration-file

  1. Add the following line to your vimrc file to enable line numbers:

<strong>set number</strong>
  1. Save and exit the Vimrc file by typing :wq and pressing Enter.

editing-configuration-file-to-view-line-numbers

  1. Now open the text file in vim by typing the following command:

<strong>vim filename.txt</strong>

Replace filename with the filename in which you made changes.

opening file in vim
  1. The output will be:
displaying line numbers by default

2. vim-airline Plugin

vim-airline is a powerful status bar plugin for Vim that provides valuable information and enhancements to your editing environment. Among its features, vim-airline offers the ability to display line numbers in a visually appealing way. Here’s how to install and utilize vim-airline for line numbering:

  1. Open your vim configuration file.
  2. Add the following line to your configuration file to install vim-airline:

<strong>call plug#begin('~/.vim/plugged')</strong>
<strong>Plug 'vim-airline/vim-airline'</strong>
<strong>call plug#end()</strong>
  1. Save the configuration file and exit.
adding plugin to vim
  1. Restart Vim to apply the changes.
  2. Open Vim, and you will see the status bar at the bottom of the editor window with line numbers displayed.
viewing line numbers in vim using airline plugin

3. Activating Relative Line Numbers

Enabling relative line numbers in Vim offers a dynamic and context-aware way to navigate and reference lines. This method provides a visual representation of line relationships, making it easier to navigate through code and maintain a sense of line hierarchy. To enable relative line numbers in Vim, follow these steps:

  1. Open the file in which you want to add the relative number.
opening file
  1. Enter the following command in Vim’s command mode: