PLZZ LET ME KNOW HOW TO COMMENT MULTIPLE LINES IN A VI EDITOR???

PLZZ LET ME KNOW HOW TO COMMENT MULTIPLE LINES IN A VI EDITOR???

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

remove lines

I have a file containing 50 lines.

I want to comment line number 4 to 8 and line number 12 to 20 in same time or in one query.

how can i do that kindly update..

REgards
Linux Lover

use '|' to seperate vim commands

'|' can be used to separate commands, so you can give multiple commands in one line. If you want to use '|' in an argument, precede it with '\'.

:4,8 s/^/#/ | 12,20 s/^/#/

No need to count lines in regular vi

Instead of counting lines ( using: .,+N ) one could also use a search ( .,/WORDONTHELASTLINE/ ),

so

this is line 1
this is line 2
this is line three
this is line 4

could be commented by putting the cursor on line 1 and using:

.,/three/ s/^/#/g

commenting multiple lines in vi

Using
#if 0
Lines to be commented

#endif

is much easier....

Commenting multiple lines in VI editor...

To comment out multiple lines while writing scripts under vi where "#" is the comment marker.

:.,+N s/^/#/g

Where "N" is number of lines to be commented after the current cursor location inclusive of the current line.

With vim

You can also use Visual Mode if you don't want to count lines :

Press [Esc] key
Use arrows to move cursor to the beginning of your paragraph
Press [v] to enter Visual Mode
Use arrows to select all the lines you want to comment
Then type the following command :

:'<,'>s/^/#/g

Note : when you hit ':' in Visual Mode, ":'<,'>" is added automatically.

To remove comment, same procedure but :

:'<,'>s/^#//g

thx

Thank you!

Comment