1

I love using the :lgrep command in Vim to create a location list for the current buffer. For example I can use it with a Perl regex by doing:

:lgrep -P 'pattern' %

However, I don't like the fact that the results of the grep are displayed, obscuring my Vim session, after the grep completes. I want the results to be placed into the location list window, but for the output of the grep (to the screen) to be suppressed. Normally, after the grep is complete, Vim hides all windows and displays the results of the grep in my terminal. Then I have to Press ENTER or type command to continue to get back to the Vim session.

This is annoying.

I usually immediately open a location list window and navigate the results using that window. I want to suppress the displaying of the grep results and then prompting me to hit ENTER to continue.

Is this possible?

5

Yes, just prepend :silent to the command:

:silent lgrep -P 'pattern' %

Excerpt from :help :silent:

  ":silent" will also avoid the hit-enter prompt.  When
  using this for an external command, this may cause the
  screen to be messed up.  Use |CTRL-L| to clean it up
  then.
  • 1
    This is great, except for being forced to use Ctrl-l to do cleanup afterwards. Is there any way for it to auto-repaint or something. – Michael Goldshteyn Mar 19 '14 at 16:24
  • 2
    You could try :exe 'silent lgrep -P 'pattern' %' | redraw! – Ingo Karkat Mar 20 '14 at 7:18
0

You could use :lvim instead of :lgrep.

Because it uses an internal routine it doesn't suspend Vim and doesn't force you to hit <CR> or :redraw anything:

:lvim pattern % | lw

And for a really low-tech approach:

:il[ist] pattern
:n <------------------- your chosen line number

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.