<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000'>Oops, when I typed<div>:s/^/# /</div><div>I meant:</div><div>:.,$s/^/# /<br>dot-comma-dollar in front of the s means from the current line to the last line. What was in my mind at the time was that you didn't need to know the actual line numbers.</div><div><br></div><div>I like the visual block method too. You can combine that with the :r! or !! I mentioned to read in the mysql output from within vim. </div><div><br></div><div>I was also thinking about using :! mysql ....>> name.pl from inside vim when I mentioned having to do a write before hand. I see now you meant typing the mysql from the shell. <br><hr id="zwchr"><div style="color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From: </b>"Scott Plante" <splante@insightsys.com><br><b>To: </b>"Atlanta Linux Enthusiasts" <ale@ale.org><br><b>Sent: </b>Tuesday, February 5, 2013 9:12:38 PM<br><b>Subject: </b>Re: [ale] Appending in VIM<br><br><style>p { margin: 0; }</style><div style="font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000"><font face="arial, helvetica, sans-serif" size="3">I have two further incremental improvements.</font><div><font face="arial, helvetica, sans-serif"><br></font><div><font face="arial, helvetica, sans-serif">First:</font></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 12pt;">As JD and Chris noted, you can insert with :s command. However, in this case you know you're going to the end of the file because you used >>, so if you put your cursor on the top line, you can just do:</div></div><div><div style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 12pt;"> :s/^/# /</div></div><div><div><font face="arial, helvetica, sans-serif" size="3">No need for the final g--that says do all </font><font face="arial, helvetica, sans-serif">occurrences</font><font face="arial, helvetica, sans-serif" size="3"> on the line and there's only one start of line per line.</font></div></div><div><div><font face="arial, helvetica, sans-serif">Of course, to use this method, you have to write the file (:w) before you begin, and re-read (:e) after the command execution, but before the :s.</font></div></div><div><div><font face="arial, helvetica, sans-serif">And, you still need to move the new comment lines to where you want them in the script, if it's not the end.</font></div></div></blockquote><div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">Second:</font></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div><font face="arial, helvetica, sans-serif">You can use :r! to insert the output of a command below your current line, so you could just go to the line above where you want your new comment and type</font></div></div><div><div><font face="arial, helvetica, sans-serif">:r! mysql .... |sed 's/^/\# '</font></div></div><div><div><font face="arial, helvetica, sans-serif">And your new comment block will appear where you want it in the script, without a special :w and :e. You need the backslash before the # in the sed because # is replaced with the <i>other</i> file you're editing. For example, if you vi a.pl, then type :e b.pl to edit that script, :r # will read a.pl into b.pl edit buffer on the line below your cursor.</font></div></div></blockquote><div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">By the way, I often just use !! instead of :r! . !! says send the current line as stdin to the following command, and replace the current line with the command's stdout. I usually find it quicker to create a blank line and do the !! on that line. You can also use ! with a line range to, say, do sorting (replace lines with their sorted equivalent).</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><br></div><div><font face="arial, helvetica, sans-serif">Scott<br></font><hr id="zwchr" style="color: rgb(0, 0, 0); font-family: arial, helvetica, sans-serif; font-size: 12pt;"><div style="color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-size: 12pt; font-weight: normal; font-style: normal; text-decoration: initial;"><b>From: </b>"Alex Carver" <agcarver+ale@acarver.net><br><b>To: </b>ale@ale.org<br><b>Sent: </b>Tuesday, February 5, 2013 7:00:10 PM<br><b>Subject: </b>Re: [ale] Appending in VIM<br><br>On 2/5/2013 15:09, Chris Fowler wrote:<br>> On 02/05/2013 04:49 PM, JD wrote:<br>>> If you know the line number range, doesn't this work?<br>>><br>>> 7,53s/$/#_/g<br>><br>> That is one way and it works, but need to use ^ for beginning instead<br>> of the end of line.<br>><br><br>There's also visual-block mode. Move to the first column of the first <br>line you want to change, Ctrl-V then move the cursor down to the last <br>line (you can use any cursor movement such as [n]j to move n lines down <br>or use / to search for a keyword but then that will highlight extra <br>columns so use 'h' to shrink back to one column). Now use captial i (I) <br>to do a visual-block insert, type in the # once, press <ESC>, and move <br>away from the line.<br><br>Or you can do it during the mysql command and avoid hand editing <br>completely. Pipe through sed on its way to the file:<br><br>mysql .... | sed 's/^/#/g' >> perlfile.pl<br>_______________________________________________<br>Ale mailing list<br>Ale@ale.org<br>http://mail.ale.org/mailman/listinfo/ale<br>See JOBS, ANNOUNCE and SCHOOLS lists at<br>http://mail.ale.org/mailman/listinfo<br></div><br></div></div></div></div></div><br></div></div></body></html>