LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-06-2006, 02:40 PM   #1
shamgar03
Member
 
Registered: Jul 2004
Distribution: Gentoo, CentOS
Posts: 92

Rep: Reputation: 15
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?
 
Old 06-06-2006, 03:20 PM   #2
shamgar03
Member
 
Registered: Jul 2004
Distribution: Gentoo, CentOS
Posts: 92

Original Poster
Rep: Reputation: 15
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.
 
Old 06-06-2006, 03:41 PM   #3
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
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.
 
Old 06-06-2006, 04:49 PM   #4
shamgar03
Member
 
Registered: Jul 2004
Distribution: Gentoo, CentOS
Posts: 92

Original Poster
Rep: Reputation: 15
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
commenting more than one line in VI editor newbloggy Linux - Software 1 04-18-2006 07:09 AM
php commenting, and api generation dakomoon Programming 2 12-11-2005 11:13 PM
proper commenting in C joesbox Programming 6 02-13-2005 11:11 PM
Finding lines in file1,but not in file 2 subu_s Programming 2 12-14-2004 09:56 AM
vim: mark end-of-line? trim blank lines? prell Linux - Software 3 09-20-2004 11:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration