• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Show & Hide Line Numbers in Vim / Vi

Thumbnail for Amber ChenThumbnail for Amber ChenThumbnail for Amber ChenThumbnail for Amber Chen
Amber Chen

Amber Chen

Senior Engineer,, Lyft

Published: 1/31/2024

About Terminus

The Short Answer

In vim, display or showing line numbers is synonymous with setting line numbers:

  • set number or set nu will show or turn on line numbers
  • set nonumber or set nonu will hide the line numbers
  • set relativenumber or set rnu will show line numbers relative to the cursor position
  • set nonumber norelativenumber or set nornu will hide line numbers
  • set number! will toggle the line numbers on/off
  • set relativenumber! will toggle the relative line numbers on/off

Showing Absolute Line Numbers

For long files, it can be easy to lose track of the code in question, but having line numbers can be a useful point of reference. 

Use the command, set number to show the absolute line numbers in the editor. 

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Showing Relative Line Numbers

It’s possible to also view line numbers relative to the current line where the cursor is located. This is used less commonly than absolute line numbers but can be helpful when copy and pasting a code block.

Use the command, set relativenumber to show the relative line numbers in the editor. 

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Toggling Line Numbers

To toggle between showing and hiding line numbers, add a bang ! to the end of the command.

  • set number! for absolute line numbers
  • set relativenumber! for relative line numbers

Showing Line Numbers by Default

Edit the ~/.vimrc file by using this command: vim ~/.vimrc

Then add set number to the file and save and quit. Then any new vi editors will show absolute line numbers by default.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

What’s Next?

Now that you know how to show line numbers, you may be wondering how to jump to a specific line number. Read more tips and tricks on vim in our collection of posts about vim.

Written by

Thumbnail for Amber ChenThumbnail for Amber ChenThumbnail for Amber ChenThumbnail for Amber Chen
Amber Chen

Amber Chen

Senior Engineer,, Lyft

Filed Under

Related Articles

Vim Find And Replace

You can use either the substitute command or the slash and dot method to search for patterns and replace with different values.

VimVi
Thumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory Kim
Glory Kim

Vim Modes

Learn about seven of Vim’s modes

VimVi
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Vim / Vi Page Up and Down Controls

Quick reference for Vim's page up and down controls

VimVi
Thumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory Kim
Glory Kim

Copy & Paste in Vim / Vi

Copy (Yank), Paste (Put) and Cut (Delete) in Vim

VimVi
Thumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica Wang
Jessica Wang

Undo & Redo in Vim / Vi

Keyboard shortcuts and summary of how Vim tracks changes

VimVi
Thumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica WangThumbnail for Jessica Wang
Jessica Wang

Select all in Vim / Vi

Select all and copy, paste, or delete the contents

VimVi
Thumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory KimThumbnail for Glory Kim
Glory Kim

Searching in Vim

Search forward, backward, case insensitive, and more

VimVi
Thumbnail for Neeran GulThumbnail for Neeran GulThumbnail for Neeran GulThumbnail for Neeran Gul
Neeran Gul

Go To End of File in Vim / Vi

Select and delete to the end of a file in Vim

VimVi
Thumbnail for Preston Tunnell WilsonThumbnail for Preston Tunnell WilsonThumbnail for Preston Tunnell WilsonThumbnail for Preston Tunnell Wilson
Preston Tunnell Wilson

How to delete lines in Vim / Vi

The best answer depends on which mode you use

VimVi
Thumbnail for Andrew CarlsonThumbnail for Andrew CarlsonThumbnail for Andrew CarlsonThumbnail for Andrew Carlson
Andrew Carlson

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for nullThumbnail for nullThumbnail for nullThumbnail for null