John Degen wrote:
> I'm having trouble understanding why there is a period before
> "w" in the following command:
>
> :'a,'b g/^Error/ .w >> errors.txt
Others have explained that '.' is a range specifying the current
line. However, the reason it is needed is that the :w command
assume a default range of '%' (same as '1,$' which is all
lines). If the . is omitted, the w will write the whole buffer
to the end of file errors.txt.
Another approach to the above problem is:
:let @a = ''
:'a,'b g/^Error/ y A
The first command sets register a to '' (empty).
The second executes 'y A' on all wanted lines, and that yanks
the line to register A (which appends to register a).
The default range for y is . (current line) so no range need be
specified.
I am currently using the following for this kind of thing as
while simple is good, the convenience is very appealing:
:'a,'b CopyLines - ^Error
from tip http://vim.wikia.com/wiki/Copy_search_matches
BTW I'm going to replace the script in that tip soon as I have
found a couple of corner cases where it fails.
John
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Friday, May 25, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment