vi show line numbers in linux

Previous
Next

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.
Vi editor without line number

1. Press ESC key.
2. Press : and type “set number”
3. Press enter

vi editor with line number

Alternatively, you can do follow as well’
1. Press ESC key.
2. Press : and type “set nu”
3. Press enter


Here are the steps to hide line numbers in vi/vim text editor.


1. Press ESC key.
2. Press : and type “set nonumber”
3. Press enter

vi editor with no number

Alternatively, you can do follow as well’
1. Press ESC key.
2. Press : and type “set nu!”
3. 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.

Previous
Next

Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.




Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog