Help with @/ (last search) in vimgrep command

6 views
Skip to first unread message

Lewis Thompson

unread,
Dec 5, 2008, 12:22:56 PM12/5/08
to vim_use
Hi

I would like to create a command to use vimgrep on my last search
(made with /)

I've tried:

command Gr vimgrep /@//g %

but this doesn't work. Can anybody help me out with how to do this
correctly?

thanks, Lewis

John Beckett

unread,
Dec 5, 2008, 7:50:35 PM12/5/08
to vim...@googlegroups.com
Lewis Thompson wrote:
> I would like to create a command to use vimgrep on my last
> search (made with /)
>
> I've tried:
>
> command Gr vimgrep /@//g %

command Gr execute 'vimgrep /'.@/.'/g %'

John

Tony Mechelynck

unread,
Dec 5, 2008, 8:02:12 PM12/5/08
to vim...@googlegroups.com

Method I.

Don't write any user-command. Just hit Ctrl-R followed by / between the
two slashes delimiting your vimgrep pattern.

See "help c_CTRL-R"

Method II.

command -bar -nargs=+ -complete=file
\ Gr exec 'vimgrep /' . @/ . '/g' <q-args>

then ":Gr %" will search the current file, and ":Gr *.[ch]" will search
*.c and *.h files, etc.

The idea is that @/ (when used to mean the latest search pattern) is a
variable name, not a string value.

See
:help :command
:help :execute
:help expression-syntax
then scroll down a page or so
until you see the various kinds of |expr9|


Best regards,
Tony.
--
The ladies men admire, I've heard,
Would shudder at a wicked word.
Their candle gives a single light;
They'd rather stay at home at night.
They do not keep awake till three,
Nor read erotic poetry.
They never sanction the impure,
Nor recognize an overture.
They shrink from powders and from paints ...
So far, I've had no complaints.
-- Dorothy Parker

Reply all
Reply to author
Forward
0 new messages