Thursday, March 31, 2016

Re: Using g://w to filter a buffer

Axel Bender wrote:
> Given the following description in the docs
>
> "The global commands work by first scanning through the [range] lines and
> marking each line where a match occurs (for a multi-line pattern, only the
> start of the match matters).
> In a second scan the [cmd] is executed for each marked line with its line
> number prepended."
>
> shouldn't this filter a buffer
>
> "g/some pattern/w! >> some_file.txt"
>
> to a new file, considering that
>
> ".w! >> some_file.txt"
>
> works?
>
What's not working? Here's an explanation:

g/some pattern/ For every line in the file that matches the pattern
w! >> some_file.txt write the entire file to some_file.txt

Assuming you've got more than one match, you'll get more than one copy
of the entire buffer in the file, appended to whatever happened to be
there before the command.
Perhaps you wanted to use :g/some pattern/.w! >> some_file.txt ?

Regards,
Chip

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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: