:grep & :cope

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

:grep & :cope

A. S. Budden
Eh up,

At the moment, if I run (for example) ":grep asb_pwmgen *.vhd", I get
the output from the grep command and then if I want the quickfix
window open, I have to type ":cope" to make it appear.  Is there a
setting somewhere that makes ":grep" run silently and the quickfix
window open automatically -- it's generally not of much use to me to
see the list of matches without then being able to select one from
that list.

I guess I could make some new command like

:command -nargs=* Grep grep <args><cr><cr>:cope

or something like that (the above doesn't actually work...), but I was
hoping there would be a neater solution (like an option) using :grep
unchanged.

Many thanks for any help,

Al
Reply | Threaded
Open this post in threaded view
|

Re: :grep & :cope

A.J.Mechelynck
A. S. Budden wrote:

> Eh up,
>
> At the moment, if I run (for example) ":grep asb_pwmgen *.vhd", I get
> the output from the grep command and then if I want the quickfix
> window open, I have to type ":cope" to make it appear.  Is there a
> setting somewhere that makes ":grep" run silently and the quickfix
> window open automatically -- it's generally not of much use to me to
> see the list of matches without then being able to select one from
> that list.
>
> I guess I could make some new command like
>
> :command -nargs=* Grep grep <args><cr><cr>:cope
>
> or something like that (the above doesn't actually work...), but I was
> hoping there would be a neater solution (like an option) using :grep
> unchanged.
>
> Many thanks for any help,
>
> Al

From the top of my head, I don't see any way to open the quickfix window
as part of the :grep command (unless, as you said, by defining a
user-command to infoke both :grep and :copen in turn); but to enconomize
your "typing work" you can use a mapping, e.g.

        :map <F9> :copen<CR>

If your user command above doesn't work, try something slightly
different, maybe in the line of (untested)

        :command -args=* Grep exe "grep" <q-args> | copen


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

RE: :grep & :cope

David Fishburn
In reply to this post by A. S. Budden
 

> -----Original Message-----
> From: A. S. Budden [mailto:[hidden email]]
> Sent: Tuesday, October 04, 2005 6:26 AM
> To: vim help
> Subject: :grep & :cope
>
> Eh up,
>
> At the moment, if I run (for example) ":grep asb_pwmgen
> *.vhd", I get the output from the grep command and then if I
> want the quickfix window open, I have to type ":cope" to make
> it appear.  Is there a setting somewhere that makes ":grep"
> run silently and the quickfix window open automatically --
> it's generally not of much use to me to see the list of
> matches without then being able to select one from that list.
>
> I guess I could make some new command like
>
> :command -nargs=* Grep grep <args><cr><cr>:cope
>
> or something like that (the above doesn't actually work...),
> but I was hoping there would be a neater solution (like an
> option) using :grep unchanged.

I do something similar with the Cscope support in Vim.

    nnoremap g<C-\> :silent! cs find 0
<C-R>=expand("<cword>")<CR><CR>:cwindow<CR>

So I am not aware of any option to do this, but I call :cwindow, not :copen,
since it no results are found, it will not open the window.  I like this
better since I don't have to close it manually.

HTH,
Dave


--
Do you use Vim to edit SQL?
<Plug>
Check the description of these plugins:
dbext.vim - Provides database access to 10 databases (Oracle, Sybase, SQL
Server, MySQL,...) (http://www.vim.org/scripts/script.php?script_id=356)
SQLUtilities - Formatting SQL, generate - columns lists, procedures for
databases (http://www.vim.org/scripts/script.php?script_id=492)
sql.vim - SQL indent file for Sybase ASA and Oracle
(http://www.vim.org/scripts/script.php?script_id=495)
Intellisense for Vim : SQL, C++, CSharp, Java, JSP, XML, HTML
(http://www.vim.org/scripts/script.php?script_id=747)
</Plug>


Reply | Threaded
Open this post in threaded view
|

Re: :grep & :cope

A. S. Budden
On 04/10/05, David Fishburn <[hidden email]> wrote:

>
>
> > -----Original Message-----
> > From: A. S. Budden [mailto:[hidden email]]
> > Sent: Tuesday, October 04, 2005 6:26 AM
> > To: vim help
> > Subject: :grep & :cope
> >
> > Eh up,
> >
> > At the moment, if I run (for example) ":grep asb_pwmgen
> > *.vhd", I get the output from the grep command and then if I
> > want the quickfix window open, I have to type ":cope" to make
> > it appear.  Is there a setting somewhere that makes ":grep"
> > run silently and the quickfix window open automatically --
> > it's generally not of much use to me to see the list of
> > matches without then being able to select one from that list.
> >
> > I guess I could make some new command like
> >
> > :command -nargs=* Grep grep <args><cr><cr>:cope
> >
> > or something like that (the above doesn't actually work...),
> > but I was hoping there would be a neater solution (like an
> > option) using :grep unchanged.
>
> I do something similar with the Cscope support in Vim.
>
>     nnoremap g<C-\> :silent! cs find 0
> <C-R>=expand("<cword>")<CR><CR>:cwindow<CR>
>
> So I am not aware of any option to do this, but I call :cwindow, not :copen,
> since it no results are found, it will not open the window.  I like this
> better since I don't have to close it manually.
>
> HTH,
> Dave
>

Ok, thanks (to both Dave & Tony) for the advice.

Al
Reply | Threaded
Open this post in threaded view
|

RE: :grep & :cope

jason heddings-2
I map mine to a function that keeps track if the window was open or not:

" toggles the quickfix window.
command -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
  if exists("g:qfix_win") && a:forced == 0
    cclose
    unlet g:qfix_win
  else
    copen 10
    let g:qfix_win = bufnr("$")
  endif
Endfunction

Then I can do :QFix to toggle the window open, or :QFix! to force it open.
There is probably a better way to do this (i.e. scan the windows to see if
it was open or not), but this works pretty well.  You may end up out of
sync, though, if you don't use this function to open / close the window.

HTH,
--jah


-----Original Message-----
From: A. S. Budden [mailto:[hidden email]]
Sent: Tuesday, 04 October, 2005 08:54
To: vim help
Subject: Re: :grep & :cope

On 04/10/05, David Fishburn <[hidden email]> wrote:

>
>
> > -----Original Message-----
> > From: A. S. Budden [mailto:[hidden email]]
> > Sent: Tuesday, October 04, 2005 6:26 AM
> > To: vim help
> > Subject: :grep & :cope
> >
> > Eh up,
> >
> > At the moment, if I run (for example) ":grep asb_pwmgen *.vhd", I
> > get the output from the grep command and then if I want the quickfix
> > window open, I have to type ":cope" to make it appear.  Is there a
> > setting somewhere that makes ":grep"
> > run silently and the quickfix window open automatically -- it's
> > generally not of much use to me to see the list of matches without
> > then being able to select one from that list.
> >
> > I guess I could make some new command like
> >
> > :command -nargs=* Grep grep <args><cr><cr>:cope
> >
> > or something like that (the above doesn't actually work...), but I
> > was hoping there would be a neater solution (like an
> > option) using :grep unchanged.
>
> I do something similar with the Cscope support in Vim.
>
>     nnoremap g<C-\> :silent! cs find 0
> <C-R>=expand("<cword>")<CR><CR>:cwindow<CR>
>
> So I am not aware of any option to do this, but I call :cwindow, not
> :copen, since it no results are found, it will not open the window.  I
> like this better since I don't have to close it manually.
>
> HTH,
> Dave
>

Ok, thanks (to both Dave & Tony) for the advice.

Al

Reply | Threaded
Open this post in threaded view
|

RE: :grep & :cope

Hari Krishna Dara
In reply to this post by A. S. Budden

On Tue, 4 Oct 2005 at 9:50am, jason heddings wrote:

> I map mine to a function that keeps track if the window was open or not:
>
> " toggles the quickfix window.
> command -bang -nargs=? QFix call QFixToggle(<bang>0)
> function! QFixToggle(forced)
>   if exists("g:qfix_win") && a:forced == 0
>     cclose
>     unlet g:qfix_win
>   else
>     copen 10
>     let g:qfix_win = bufnr("$")
>   endif
> Endfunction
>
> Then I can do :QFix to toggle the window open, or :QFix! to force it open.
> There is probably a better way to do this (i.e. scan the windows to see if
> it was open or not), but this works pretty well.  You may end up out of
> sync, though, if you don't use this function to open / close the window.
>
> HTH,
> --jah

If you take advantage of the autocommands, then you can avoid them going
out of sync, and you can freely intermix the built-in commands and calls
to your function.

aug QFixToggle
au!
au BufWinEnter quickfix let g:qfix_win = bufnr('$')
au BufWinLeave * if exists('g:qfix_win') && expand('<abuf>') == g:qfix_win |
unlet! g:qfix_win | endif
aug END

Your function will then become simply:

command -bang -nargs=? QFix call QFixToggle(<bang>0)
function! QFixToggle(forced)
  if exists("g:qfix_win") && a:forced == 0
    cclose
  else
    copen 10
  endif
endfunction

--
HTH,
Hari

>
>
> -----Original Message-----
> From: A. S. Budden [mailto:[hidden email]]
> Sent: Tuesday, 04 October, 2005 08:54
> To: vim help
> Subject: Re: :grep & :cope
>
> On 04/10/05, David Fishburn <[hidden email]> wrote:
> >
> >
> > > -----Original Message-----
> > > From: A. S. Budden [mailto:[hidden email]]
> > > Sent: Tuesday, October 04, 2005 6:26 AM
> > > To: vim help
> > > Subject: :grep & :cope
> > >
> > > Eh up,
> > >
> > > At the moment, if I run (for example) ":grep asb_pwmgen *.vhd", I
> > > get the output from the grep command and then if I want the quickfix
> > > window open, I have to type ":cope" to make it appear.  Is there a
> > > setting somewhere that makes ":grep"
> > > run silently and the quickfix window open automatically -- it's
> > > generally not of much use to me to see the list of matches without
> > > then being able to select one from that list.
> > >
> > > I guess I could make some new command like
> > >
> > > :command -nargs=* Grep grep <args><cr><cr>:cope
> > >
> > > or something like that (the above doesn't actually work...), but I
> > > was hoping there would be a neater solution (like an
> > > option) using :grep unchanged.
> >
> > I do something similar with the Cscope support in Vim.
> >
> >     nnoremap g<C-\> :silent! cs find 0
> > <C-R>=expand("<cword>")<CR><CR>:cwindow<CR>
> >
> > So I am not aware of any option to do this, but I call :cwindow, not
> > :copen, since it no results are found, it will not open the window.  I
> > like this better since I don't have to close it manually.
> >
> > HTH,
> > Dave
> >
>
> Ok, thanks (to both Dave & Tony) for the advice.
>
> Al
>
>
>


               
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

RE: :grep & :cope

jason heddings-2
I turned this into a plugin for those who are interested.
http://www.vim.org/scripts/script.php?script_id=1375

Thanks for the help on the auto-commands!  This is much nicer...

--jah
 

-----Original Message-----
From: Hari Krishna Dara [mailto:[hidden email]]
Sent: Tuesday, 04 October, 2005 11:24
To: jason heddings
Cc: 'A. S. Budden'; 'vim help'
Subject: RE: :grep & :cope


On Tue, 4 Oct 2005 at 9:50am, jason heddings wrote:

> I map mine to a function that keeps track if the window was open or not:
>
> " toggles the quickfix window.
> command -bang -nargs=? QFix call QFixToggle(<bang>0) function!
> QFixToggle(forced)
>   if exists("g:qfix_win") && a:forced == 0
>     cclose
>     unlet g:qfix_win
>   else
>     copen 10
>     let g:qfix_win = bufnr("$")
>   endif
> Endfunction
>
> Then I can do :QFix to toggle the window open, or :QFix! to force it open.
> There is probably a better way to do this (i.e. scan the windows to
> see if it was open or not), but this works pretty well.  You may end
> up out of sync, though, if you don't use this function to open / close the
window.
>
> HTH,
> --jah

If you take advantage of the autocommands, then you can avoid them going out
of sync, and you can freely intermix the built-in commands and calls to your
function.

aug QFixToggle
au!
au BufWinEnter quickfix let g:qfix_win = bufnr('$') au BufWinLeave * if
exists('g:qfix_win') && expand('<abuf>') == g:qfix_win | unlet! g:qfix_win |
endif aug END

Your function will then become simply:

command -bang -nargs=? QFix call QFixToggle(<bang>0) function!
QFixToggle(forced)
  if exists("g:qfix_win") && a:forced == 0
    cclose
  else
    copen 10
  endif
endfunction

--
HTH,
Hari

>
>
> -----Original Message-----
> From: A. S. Budden [mailto:[hidden email]]
> Sent: Tuesday, 04 October, 2005 08:54
> To: vim help
> Subject: Re: :grep & :cope
>
> On 04/10/05, David Fishburn <[hidden email]> wrote:
> >
> >
> > > -----Original Message-----
> > > From: A. S. Budden [mailto:[hidden email]]
> > > Sent: Tuesday, October 04, 2005 6:26 AM
> > > To: vim help
> > > Subject: :grep & :cope
> > >
> > > Eh up,
> > >
> > > At the moment, if I run (for example) ":grep asb_pwmgen *.vhd", I
> > > get the output from the grep command and then if I want the
> > > quickfix window open, I have to type ":cope" to make it appear.  
> > > Is there a setting somewhere that makes ":grep"
> > > run silently and the quickfix window open automatically -- it's
> > > generally not of much use to me to see the list of matches without
> > > then being able to select one from that list.
> > >
> > > I guess I could make some new command like
> > >
> > > :command -nargs=* Grep grep <args><cr><cr>:cope
> > >
> > > or something like that (the above doesn't actually work...), but I
> > > was hoping there would be a neater solution (like an
> > > option) using :grep unchanged.
> >
> > I do something similar with the Cscope support in Vim.
> >
> >     nnoremap g<C-\> :silent! cs find 0
> > <C-R>=expand("<cword>")<CR><CR>:cwindow<CR>
> >
> > So I am not aware of any option to do this, but I call :cwindow, not
> > :copen, since it no results are found, it will not open the window.  
> > I like this better since I don't have to close it manually.
> >
> > HTH,
> > Dave
> >
>
> Ok, thanks (to both Dave & Tony) for the advice.
>
> Al
>
>
>


               
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com