On 2014-10-26 16:27, Michael Henry wrote:
> On 10/26/2014 02:32 PM, Tim Chase wrote:
> > :g/^\n\</+;'}-j
>
> I understand how the above works, but I can't find justification
> for it in Vim's help. I'd break it down as follows:
>
> :g Begin "global" command
> /^\n\</ Find blank line followed by start of word
> + Go forward one line to start of paragraph
> ; Set cursor to above-calculated start of range
> '} Move to blank line after paragraph
> - Go backward one line to end of paragraph
> j Join lines in paragraph delimited by the range
>
> But looking at ``:help :g``, I see:
>
> :[range]g[lobal]/{pattern}/[cmd]
>
> The analysis above requires some features of a full-bown "range"
> (:help range) instead of just the ``/pattern/`` (:help pattern)
> that is permissible according to the help for ``:g``. Am I
> missing something here? I can't tell if the documentation for
> the global command should be expanded to cover this
> functionality beyond a simple pattern, or if the ability to use
> range-like features is accidental and not supposed to be part of
> the global command.
It's definitely part of the command. The trick is knowing that
"[cmd]" can include a range relative to the line(s) matched by the :g
command. I had to dig around to find references in the help, but
I found a couple examples using a range as part of the [cmd]:
:help collapse
as well as around lines 411 & 448 of ":help usr_25.txt".
I do this all the time as it's very powerful. It's been in vi/ex as
long as I know/remember, and even works in the venerable "ed".
The only gotcha that I've found is when your relative ranges walk off
the top/bottom of the file, triggering the aforementioned edge-cases.
-tim
--
--
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.
Sunday, October 26, 2014
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment