1 Dec 2010 01:17
Re: filter txt file based on start and ending marks
Tim Chase <vim <at> tim.thechases.com>
2010-12-01 00:17:16 GMT
2010-12-01 00:17:16 GMT
On 11/30/2010 04:01 PM, bboyjkang wrote: >> :g/interesting/sil! ?start?,/end/s/^/XXX/ >> :v/^XXX/d >> :%s/^XXX > > Is the “start” and “end” something you have to add yourself? Is it > possible to do this: Let’s say that once I find the pattern > “interesting”, I’d like to select the line that contains > “interesting”, or maybe include the line above and the line below that > line that contains “interesting”, for a total of 3 lines, or perhaps > the entire paragraph that contains “interesting”. Then, “start” is > automatically put at the top of the paragraph/line(s), and “end” is > put at the bottom of the paragraph/line(s). Now, I can do pattern > matches or substitutions only on ranges between “start” and “end” that > surround “interesting”. (Rearranged to trimmed inline-quoting rather than top-posting, as is preferred on the mailing-list) Yes, you can give other relative ranges. Note that it breaks down as :g/pattern/action_to_perform_on_matching_lines where action happens to be <range>s/foo/bar/ (prefixed with "sil!" as previously detailed) and where <range> happens to be "search backwards for pattern A, through searching forwards to pattern B". For the line above/below version, you(Continue reading)
RSS Feed