On 2013-05-08, Erik Christiansen wrote:
> On 07.05.13 10:58, Gary Johnson wrote:
> > On 2013-05-08, Erik Christiansen wrote:
> > You might find this script, which I've named vimgrep, useful.
> > 
> >     #!/bin/bash
> > 
> >     tmp=$(mktemp)
> > 
> >     cat > $tmp
> >     exec < /dev/tty
> >     vim --cmd 'let &efm=&gfm' -q $tmp "$@"
> >     rm $tmp
> > 
> > It's invoked like this:
> > 
> >     grep -Hn <whatever other options and files you want> | vimgrep
> 
> That hangs here, because /dev/tty is not used. (Confirmed by fuser)
> Depending on which xterm it's invoked in, it'll be /dev/tty1 ... 6.
> If I knew what the redirection is expected to achieve, then we could
> probably hack something which works.

I'm not sure of the correct terminology to use here, but /dev/tty is
an alias for the tty actually used by your terminal.  So any process
can access /dev/tty and it will get the correct tty allocated to its
process group.  You do not need to specify a particular device, such
as /dev/tty1, etc.

If /dev/tty is not working for you, something is wrong with your
environment.  It's at least not consistent with common Unix
practice.

The reason for the redirection is to connect vim's stdin to your
terminal.  Otherwise, vim's stdin will be connected to the script's
stdin which is a pipe and vim will be unhappy:

    Vim: Warning: Input is not from a terminal

and upon exit will leave your terminal settings messed up, e.g., no
echo.

> > All the lines that grep finds will be fed to vim as a quickfix list,
> > which you can traverse with :cn, :cp, etc., or browse with :copen.
> 
> That's what I was trying to get away from, because (as described) it was
> very clumsy to step blindly through the helpgrep hits, using those
> commands.

That's why I use the mappings I described.  Typing :cn<Enter> and
:cp<Enter> to traverse the quickfix or :helpgrep lists is just
ridiculous.  Find a pair of keys you don't use for anything else and
map them to :cn<CR> and :cp<CR>.

> I have now tried your :copen suggestion with helpgrep, but
> that splits the window into 3, introducing a great deal if visual
> clutter.

Agreed.  I don't use :copen much myself either.

> My method is much more attractive, in that it keeps the list of search
> hits visually separate, avoids those cluttered vim window splits, and
> allows any regex. (Helpgrep seemed very limited in that regard when I
> tried it, just now.)

:helpgrep is limited to single-line patterns, but other than that, I
think it will accept any Vim regex.

> Keeping the list in a separate buffer, and using "gf", re-uses vim
> commands which I use a lot. When trying the quickfix alternative,
> the need to both ":q" _and_ ":ccl", to get rid of the window
> splits, is also annoying.

Using "gf" means having to go back and forth between the window
containing the list of files and the selected file.  Using <C-N> and
<C-P> mapped to :cn<CR> and :cp<CR> just zips among all the matches.

Regards,
Gary

Reply via email to