[ale] Appending in VIM

Scott Plante splante at insightsys.com
Tue Feb 5 21:12:38 EST 2013


I have two further incremental improvements. 


First: 



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: 

:s/^/# / 

No need for the final g--that says do all occurrences on the line and there's only one start of line per line. 

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. 

And, you still need to move the new comment lines to where you want them in the script, if it's not the end. 





Second: 
<blockquote>


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 

:r! mysql .... |sed 's/^/\# ' 

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 other 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. 
</blockquote>




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). 




Scott 
----- Original Message -----

From: "Alex Carver" <agcarver+ale at acarver.net> 
To: ale at ale.org 
Sent: Tuesday, February 5, 2013 7:00:10 PM 
Subject: Re: [ale] Appending in VIM 

On 2/5/2013 15:09, Chris Fowler wrote: 
> On 02/05/2013 04:49 PM, JD wrote: 
>> If you know the line number range, doesn't this work? 
>> 
>> 7,53s/$/#_/g 
> 
> That is one way and it works, but need to use ^ for beginning instead 
> of the end of line. 
> 

There's also visual-block mode. Move to the first column of the first 
line you want to change, Ctrl-V then move the cursor down to the last 
line (you can use any cursor movement such as [n]j to move n lines down 
or use / to search for a keyword but then that will highlight extra 
columns so use 'h' to shrink back to one column). Now use captial i (I) 
to do a visual-block insert, type in the # once, press <ESC>, and move 
away from the line. 

Or you can do it during the mysql command and avoid hand editing 
completely. Pipe through sed on its way to the file: 

mysql .... | sed 's/^/#/g' >> perlfile.pl 
_______________________________________________ 
Ale mailing list 
Ale at ale.org 
http://mail.ale.org/mailman/listinfo/ale 
See JOBS, ANNOUNCE and SCHOOLS lists at 
http://mail.ale.org/mailman/listinfo 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.ale.org/pipermail/ale/attachments/20130205/2577663e/attachment-0001.html>


More information about the Ale mailing list