Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
How to Hide Line Numbers in Vim Editor
Next article icon

How to Display Line Number in vim editor in Linux

Last Updated : 02 Oct, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will cover how to make the Vim editor display or hide line numbers. First, we look at what Linux and VIM editors and why we use them, are its features and how can we use them Follow the basic VIM editor guide to get familiar with the editor followed by various options to make the vim editor display or hide line numbers and how we can change the default settings of vim editor to display or hide line numbers.

Linux

Linux was developed by Linus Torvalds in 1991 as a hobby project. It is an open-source (source code that can be used by anyone freely) kernel that is most popular and widely used in the industry as well as in personal systems. There are various operating systems based on the Linux kernel, some of the popular Linux distributions are Ubuntu, Cent OS, Red Hat, Debian, and Kali Linux.

VIM Editor

VIM stands for VI Improved (VIM) which is an improved version of the vi editor released in 1991, vi editor is a widely used text editor in Unix/Linux systems and is known for its efficiency and flexibility, vi editor was developed in 1976 by Bill Joy. There are two modes in Vim Editor:

  • Insert Mode
  • Command Mode

Basic VIM editor guide

1. Create/Edit a file using Vi editor

vi filename

2. Insert Mode

To make any changes in the file first you need to enter in the insert mode to modify the file. To get into insert mode press button 'i' to enter in insert mode.

3. Command Mode

To run any command in the vi editor you have to first enter in the command mode if you are currently in the insert mode then press Esc and then ':' colon followed by your command to run your command in the editor.

4. Basic Navigation

To navigate easily within the file vi editor provides a large number of commands which are as follows:

Key

Description

k

Moves the cursor up one line.

j

Moves the cursor down one line.

h

Moves the cursor to the left one-character position.

l

Moves the cursor to the right one-character position.

Display line numbers in vim editor

Follow the below steps to display line numbers in the vi editor:

  • Enter in command mode, Press Esc if you are in insert mode
  • Use the following command to display line numbers

:set number

alternatively,

:set nu

Example:

Screenshot-from-2023-09-25-17-50-24

Display Relative line numbers in vim editor

To display relative line number in vi editor follow the below steps, in relative line number the current line is shown as 0 and the lines above and below are incremented by 1,

  • Enter in command mode, Press Esc if you are in insert mode
  • Use the following command to display relative line numbers

:set relativenumber

Alternatively,

:set rnu

Example:

Screenshot-from-2023-09-25-17-58-54

Hide line numbers in vim editor

Follow the below steps to hide line numbers in the vim editor:

  • Enter in command mode, Press Esc if you are in insert mode
  • If you are using the relative line numbers use the following command to hide relative line numbers,

:set norelativenumber

Alternatively,

:set nornu

Use the following command to hide line numbers,

:set nonumber

Alternatively,

:set nonu

Example:

Screenshot-from-2023-09-25-18-06-09

Toggle Display between Hide line numbers

To toggle the relative line numbers use the following commands,

:set relativenumber!

Alternatively,

:set rnu!

Example:

Screenshot-from-2023-09-25-18-11-57

To toggle the line numbers use the following commands:

:set number!

Alternatively,

:set nu!

Example:

Screenshot-from-2023-09-25-18-12-12

Configure Default Settings of vim editor

To change the default settings of vim editor, we have to configure the vim editor configuration file (.vimrc), to configure the default settings follow the below steps,

  • Open the file in vim editor to configure it

vi ~/.vimrc

  • Configure the default setting as per your requirements,
  • For example, if you want to display the line numbers by default when you open the vi editor add the command :set number

Screenshot-from-2023-09-25-18-22-38

  • When you are done with configuration Press Esc to exit the insert mode
  • Use :wq command to save the changes and exit the editor

Screenshot-from-2023-09-25-18-24-17

After saving the changes whenever you open the vim editor it will open with the default settings you set in the configuration file.

Conclusion

In this article we had covered a basic vim editor guide followed by the commands for displaying line numbers, relative line number in vim editor and various commands to do the same , then how to toggle between display and hide line numbers , hide the line numbers and its command syntax along with the examples. At last we discussed some of the Frequently Asked Questions (FAQs) followed by how can we configure the default settings of the vim editor so whenever we opens the editor if loads with the default settings.


Next Article
How to Hide Line Numbers in Vim Editor
author
hardikkushwaha
Improve
Article Tags :
  • Linux-Unix
  • Geeks Premier League
  • Geeks Premier League 2023

Similar Reads

  • How to Delete Multiple Lines in vim Editor in Linux
    Vim Editor is a Linux terminal-based editor that has various advanced features for editing, but due to its terminal behavior, it is quite difficult to handle some of the operations in Vim. While making a text file, we often need to delete some unwanted lines. If the document consists of more unwante
    7 min read
  • How to comment multiple lines in Vim Editor in Linux
    Vim Editor in Linux is one of the most used text editors for writing scripts, codes, and textual data. There are different types of features offered by the Vim Editor through which we can create the text more comfortably. Various types of shortcuts, modes, and bindings are available in Vim Editor. W
    5 min read
  • How to Hide Line Numbers in Vim Editor
    In this article, we will cover how to hide line numbers in the Vim editor. First, we look at what Linux and VIM editors and why we use them, what are its features and how can we use them followed by various options to make the Vim editor hide line numbers and how we can change the default settings o
    3 min read
  • Make the VI Editor Display or Hide Line Numbers
    In this article, we will cover how to make the vi editor display or hide line numbers. First, we look at what Linux and VI editor and why we use them, what are its features and how can we use them followed by various options to make the vi editor display or hide line numbers and how we can change th
    3 min read
  • How to Edit Multiple Files in Vim Editor in Linux
    Vim, short for "Vi Improved," is a highly configurable and powerful text editor built upon the foundation of Vi. Like its predecessor, Vim offers robust support for editing multiple files simultaneously, making it an indispensable tool for developers, system administrators, and anyone working extens
    4 min read
  • How to undo in Vim editor in Linux
    Vim (short for Vi Improvised) is a popular text editor mainly used in Linux and Unix-based operating systems but due to having a CLI (command line interface), it might be difficult for new users to make use of basic features such as undo in Vim. So in this article, we will learn different ways and t
    3 min read
  • How to Edit Multiple Files in Vi Editor in Linux
    Vi, short for "visual editor," is a powerful and ubiquitous text editor in the Linux ecosystem. Among its many features, one of the most useful is its capability to edit multiple files simultaneously. This ability streamlines the editing process, especially when dealing with projects that span multi
    4 min read
  • How to Delete Multiple Lines in Vi editor
    Linux was developed by Linus Torvalds in 1991 as a hobby project. It is an open-source (source code that can be used by anyone freely) kernel that is most popular and widely used in the industry as well as in personal systems. There are various operating systems based on the Linux kernel, some of th
    5 min read
  • How to Show Line Numbers in Nano Editor?
    Nano is a popular and user-friendly text editor available on Unix-based systems, known for its simplicity and ease of use. While Nano provides essential features for text editing, such as syntax highlighting and search functionality, showing line numbers by default isn't one of them. However, it's p
    3 min read
  • How to Indent Code in Vim Editor?
    Vim is a popular text editor used by many developers for writing code, creating readme files, and writing scripts. It's open-source and offers a lot of ways to customize your experience. This makes it easier and more efficient to work with. Properly formatting and indenting your code is important be
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences