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???
Submitted by ajayyadav on Thu, 11/10/2005 - 03:41
»
- ajayyadav's blog
- Login or register to post comments
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.
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!