Sunday, October 21, 2012

How to display Line Numbers in vi or vim editor in Linux Terminal?


Want to show line numbers in the vi/ vim editor in the linux system like ubuntu..? Ok I will explain you how to show numbers in the editor of linux in two methods.

1. Temporary Method:

1. To display line numbers in the file, open the file in vim/ vi editor through terminal

2. Press [ESC] button and : (colon) and the type “set number” then press enter,
    Eg:set number
then you will get numbers in the file...

Note: If you want to hide the numbers you can type the following command by preesing [ESC] and : in the vi/vim editor
         
          :set nonumber


2. Perminent Method:

To make vim/ vi editor to show numbers defaulty follow the procedure below:

1. Open the file .vimrc in your home directory (/home/username/.vimrc) by typing as following
           $vim ~/.vimrc
    (If the file already not exists, it will be created with no text)

2. Then edit the file by typing the text below,
           
             set number
  
    Then Press ESC button and Colon button to go to command mode, then     press wq (for saving and quit the file)
             :wq

 3. Its done. All your files now defaulty will open with Line numbers

Note: If you don't want to defaulty showing Line numbers, remove the line edited in .vimrc

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...