Table of Contents
In this post, we will see how to show/hide line number in vi/vim text editor.
Let’s say you are working on any shell script and you are debugging an issue. In this scenario, line number can help you to debug issue better.
Here are the steps to show line numbers in vi/vim text editor.
$ vi sample.txt
You will see below screen.
- Press ESC key.
- Press : and type "set number"
- Press enter
Alternatively, you can do follow as well’
- Press ESC key.
- Press : and type "set nu"
- Press enter
Here are the steps to hide line numbers in vi/vim text editor.
- Press ESC key.
- Press : and type "set nonumber"
- Press enter
Alternatively, you can do follow as well’ - Press ESC key.
- Press : and type "set nu!"
- Press enter
vi show line numbers by default
If you want to permanently see line number when you start vi/vim editor.
You need to do following.
$vi ~/.vimrc
and append below line.
set number
How to open file at specific line number
Let’s say you are going through big log file and want to open file at specific line number, you can use following command.
$vi +linenumber filename
If you want to open line at 300 for file applicationLog.log, then you can use following command.
$vi +300 applicationLog.log
That’s all abut vi show line numbers in linux.