Run lgrep then immediately open Location list

14 views
Skip to first unread message

Oivvio Polite

unread,
Aug 27, 2010, 9:13:27 AM8/27/10
to vim...@googlegroups.com, v...@vim.org
I'm moving on from vim basics to the fun stuff. Just found out about vimgrep et. al.
I've set grepprg to ack-grep and after executing :lgrep I'd like to go
immediately to the "Location list" buffer, without having to press enter
after the results come back from ack-grep and without having to
explicitly execute :lopen.

Oivvio


--
http://pipedreams.polite.se/about/


Ben Fritz

unread,
Aug 27, 2010, 4:17:46 PM8/27/10
to vim_use


On Aug 27, 8:13 am, Oivvio Polite <oiv...@polite.se> wrote:
> I'm moving on from vim basics to the fun stuff. Just found out about vimgrep et. al.
> I've set grepprg to ack-grep and after executing :lgrep I'd like to go
> immediately to the "Location list" buffer, without having to press enter
> after the results come back from ack-grep and without having to
> explicitly execute :lopen.
>

Not sure about avoiding the press-enter, but you can use some of the
ideas in:

http://vim.wikia.com/wiki/Find_in_files_within_Vim

Britton Kerin

unread,
Aug 28, 2010, 3:50:38 PM8/28/10
to vim...@googlegroups.com
On Fri, Aug 27, 2010 at 6:13 AM, Oivvio Polite <oiv...@polite.se> wrote:
> I'm moving on from vim basics to the fun stuff. Just found out about vimgrep et. al.
> I've set grepprg to ack-grep and after executing :lgrep I'd like to go
> immediately to the "Location list" buffer, without having to press enter
> after the results come back from ack-grep and without having to
> explicitly execute :lopen.

This command might work for you:

:command! -nargs=+ MyLgrep execute 'silent lgrep! <args>' | lopen 42

Note that the '!' form of lgrep means 'do not jump to first match', which may
or may not be what you want.

The location list window doesn't have to be made 42 lines high, of course.

You can then invoke this command like so:

:MyLgrep export ~/.bashrc

to find for example all occurrences of the pattern 'export' in your ~/.bashrc.

You might want to map this to a key sequence:

:nnoremap <Leader>g :MyLgrep

Note that its a tiny bit more convenient if you map to 'MyLgrep ' (with a
trailing space).

Britton

Oivvio Polite

unread,
Aug 28, 2010, 5:49:31 PM8/28/10
to vim...@googlegroups.com
On Sat, Aug 28, 2010 at 12:50:38PM -0700, Britton Kerin wrote:
> :command! -nargs=+ MyLgrep execute 'silent lgrep! <args>' | lopen 42

Thank you Britton! This bit of magic works remarkably well. Unfortunatly
I've just realized that vimgrep/lgrep don't play well with
my newfound love NERDTree.

Oivvio

--
http://pipedreams.polite.se/about/


BC

unread,
Aug 28, 2010, 8:32:06 PM8/28/10
to vim_use


On Aug 28, 3:50 pm, Britton Kerin <britton.ke...@gmail.com> wrote:

> This command might work for you:
>
>      :command! -nargs=+ MyLgrep execute 'silent lgrep! <args>' | lopen 42
>


That command looked so nifty that I thought adapting it to :helpgrep
might work well:

:command! -nargs=+ MyHelp execute 'silent lhelpgrep <args>' | lopen 6

And to my amazement, it did.
This is great because I hated having to open the location window
myself every time I used helpgrep, and I had no idea how to change the
default behavior.
Thank you!
Plowing through the help files is much more pleasant now. In fact, I
wish something like that were the default behavior for :helpgrep. It
just makes more sense, it seems to me, to let users choose from the
results first, instead of jumping to the first file.




Reply all
Reply to author
Forward
0 new messages