LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   commenting more than one line in VI editor (https://www.linuxquestions.org/questions/linux-software-2/commenting-more-than-one-line-in-vi-editor-436309/)

newbloggy 04-18-2006 05:21 AM

commenting more than one line in VI editor
 
# is used to comment a line in vi editor. Can anyone help me by saying the command to comment selected number of lines in VI editor. To replace the text "hi" with "hello" in the entire file I used:

:1,$s/HI/HELLO)/g
the above command. Like this i want to comment various lines in my program. How to do this??????

berbae 04-18-2006 07:09 AM

Put the cursor to the first line of the selection you want to comment out, and mark it by typing ma,
then go to the last line of the selection and mark it by mb, then use the command:
:'a,'bs/^/#/
you can also just put the cursor to the last line of the selection without marking it, and use:
:'a,s/^/#/


All times are GMT -5. The time now is 09:29 PM.