Friday, April 13, 2012

Re: how to repeat the last :[range]g with the same range?

On 04/11/12 10:17, ping wrote:
> 1) :?pattern1?,/pattern2/g/pattern/
> you finally are satisfied with the info you grabbed, then
>
> 2) with a new defined cmd like this:
> "command! MyGrep execute 'normal! 0"ay0' | execute 'g//y A' | tabnew |
> enew | setlocal bt=nofile | put! a | nohls
> now with :MyGrep, ideally if there is no *range*, will got last matches
> and put in a neighboring tab,

First, that's a hideous command definition (to the degree I went
out to the wiki and changed it to be more legible). If you're
going to use normal mode, the canonical way to clear a register
is to use "qaq" to clear register "a". I prefer the explicit
nature of setting it in Ex with ":let @a=''".

I'd be tempted to make use of the ability to pass ranges to a
command with something like

command! -range=% MyGrep let @a='' | execute
'<line1>,<line2>g//y A' | tabnew | enew | setlocal bt=nofile |
put! a | nohls

which you can read about at

:help command-range
:help <line1>

> 3) repeat 1) on this new buffer(maybe with different range and pattern)

I'd say it's highly unlikely that one would *want* the same range
in this secondary buffer, since it's already been winnowed down
to the specified range by this point. However, the same pattern
makes sense and can be done using the blank pattern as above.

-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

No comments: