LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   VIM finding and commenting lines (https://www.linuxquestions.org/questions/linux-software-2/vim-finding-and-commenting-lines-452178/)

shamgar03 06-06-2006 02:40 PM

VIM finding and commenting lines
 
Alright so I have a large text file with a certian phrase in the middle of the line that indicates that the entire line should be commented out (it is actually a fortran source file). I was trying to work out how to make substitution do this, but I am not sure because I would like to leave the rest of the line intact, any clues?

shamgar03 06-06-2006 03:20 PM

Alright well I came up with a sort of replacement for a direct substitution. VIM has a record command mode. So I started recording, did a find, did an insert, hit esc, then stopped recording. Then I just hit @q, @@, @@... until the end of the file.

macemoneta 06-06-2006 03:41 PM

You can do it with the substitute command:

%s/^.* mace .*$/REM &/

This will find all lines that contain the string ' mace ' and put the string 'REM ' at the beginning of each.

shamgar03 06-06-2006 04:49 PM

I knew there had to be a variable for the matching string (&) thanks man. The comment out in fortran 77 (which I have the dubious honor of using) is btw.


All times are GMT -5. The time now is 02:14 AM.