On 15/06/12 05:38, ping wrote:
hi Ben:
thanks for the answer and explanation.

sorry about the html email - I didn't notice that and I think I just set
it up to text emails only. Please do let me know if there is still an
issue.

yes the answer you provided is exactly what I'm looking for, great to
learn and appreciate the explanation. Now I also understand Christian'
suggestion better :)

this
[range-start via :g],[range-end via line offset]p
method is cool...

now I'm thinking one step further :)
is there a more "scalable" method?
in my given example I only need "2 continuous lines", what if I actually
don't know (or don't want to count) how many lines it will match and I
simply just need to print them all (from the 1st to the end of matched
lines)?
[...]

In your range, the range-end can be a search command, see :help [range]

For instance, to display any lines which are between <table> and </table> included:

        :%g/<table>/.,/<\/table>/p

This assumes that you are not using embedded tables, which are a legal but rare construct.


///this doesn't work
:g#classifier-group\>.*\n\s*[1-9]\d* packets, [1-9]\d* bytes#.,line('$')p

E492: Not an editor command: ,line('$')p

Instead, to print from the line matched by :g to the end of the file, you would need g/whatever/.,$p though if there are several matches you would get repeated (overlapping) printouts.

At that point, Vim expects an ex-command (which can be preceded by a range). line( is not an ex-command but the start of an arithmetic expression. You might include it in the argument of the :eval command (q.v.) but in this case it is not necessary: In a range, the "last line" is just $ so e.g. # and 1,$ are equivalent as a range for "the whole file".

If there is only one match, you don't need :g -- for instance, to display the body of an HTML page (but not the <head> and not the trailing </html> if it is on a line by itself) you could use

        :1
        :/<body>\c/,/<\/body>\c/p

Replace p by hardcopy to type it out to the printer instead of the display.


Best regards,
Tony.
--
"If once a man indulges himself in murder, very soon he comes to think
little of robbing; and from robbing he next comes to drinking and
Sabbath-breaking, and from that to incivility and procrastination."
                -- Thomas De Quincey (1785 - 1859)

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

Reply via email to