How do I set line number in VI Editor

8,051

You could add this to your ~/.vimrc file:

set number

But if you want that to happen only on files with txt extension:

autocmd BufReadPost *.txt set number

or perhaps better, on any file which Vim detects is a text file:

autocmd FileType text set number
Share:
8,051

Related videos on Youtube

Ramesh Chand
Author by

Ramesh Chand

My Name Is Ramesh Chand I am a Windows/Linux System Admin. I have been working as the Windows/Linux System Admin since December 2006. In that time I have implemented the Active Directory Infrastructure, ADFS, SharePoint, Exchange and worked on Windows,Linux, Ubuntu,Debian,Centos,RedHat, MAC, AWS Platform, Windows Azure, SQL Server, E-jabbered, IIS and Apache Web Servers Node.js and Nginx Web Server Environment along with other tasks and responsibilities.

Updated on September 18, 2022

Comments

  • Ramesh Chand
    Ramesh Chand over 1 year

    I am using the VI editor in Ubuntu and I have maximum usage of VI editor. to see the line number in vi i am using like below:

    :set nu 
    

    I want to set it default when I open a file in vi editor, that file text open with line number by default.

    is it possible?

    Sorry for duplicate's if it but I search it lot first but not found easily also tried :colorscheme now it is showing me unknown

    • joeytwiddle
      joeytwiddle over 8 years
      By the way, you might like to ask Vim-related questions on the Vi and Vim StackExchange site
    • Ramesh Chand
      Ramesh Chand over 8 years
      vi ~/.vimrc Error detected while processing /root/.vimrc: line 3: E185: Cannot find color scheme ':default'
    • muru
      muru over 8 years
      O.o You don't have to use those settings - the relevant point is that ~/.vimrc is the file to be modified.
  • Ramesh Chand
    Ramesh Chand over 8 years
    Thanks @joeytwiddle it works !! just tried by editing # vi ~/.vimrc and enter set number in the file and Save it by :wq!