2

I've been learning about :grep, and I'd like to suppress its output and view it in a quickfix window instead as many seem to suggest. However, it seems that whenever grep produces too much output, it fills the window, and I'm unable to make the unwanted output go away without manually <C-l>.

Things I've tried:

  • silent grep! test -R . does not suppress grep output for some reason, output fills the screen

  • execute 'silent grep! test -R .' | copen The quickfix window opens, and some parts of the screen remain with my original window contents; however, all the indentations are filled with grep output, and remain until <C-l>

  • silent! execute 'silent grep! test -R .' | redraw | copen | redraw has the exact same behaviour as above

Running :set grepprg? yields grepprg=grep -n $* /dev/null. And :version yields VIM - Vi IMproved 9.0 Included patches: 1-2116.

Distro: NixOS

This seems to reproduce on vim -u NONE.

This only seems to occur when the grep output is more than one screenful; less than that, grep output is suppressed without issue.

I'm using kitty. On the other hand, I had set my TERM to xterm-256color, I guess for some compatibility reasons? Perhaps that may be related.

10
  • 2
    Check out this gist.
    – romainl
    Commented Jul 1 at 7:51
  • 1
    @Friedrich Yes, such a prompt appears, but even after dismissing the prompt with ENTER, the rest of my screen is cluttered with the garbled output of grep. This is explained by the section from romainl. Commented Jul 1 at 10:27
  • 1
    @Friedrich done, thank you.
    – romainl
    Commented Jul 1 at 14:30
  • 1
    The problem probably comes from the terminal emulator terminfo entry. I don’t have this problem either. What terminal are you using?
    – D. Ben Knoble
    Commented Jul 1 at 20:26
  • 1
    @D.BenKnoble I'm using kitty. On the other hand, I had set my TERM to xterm-256color, I guess for some compatibility reasons? Perhaps that may be related. Commented Jul 2 at 1:06

1 Answer 1

1

The problem mentioned in my gist:

The results are printed in the shell and clog our terminal's scroll buffer.

is different from the one you describe:

such a prompt appears, but even after dismissing the prompt with ENTER, the rest of my screen is cluttered with the garbled output of grep.

The former is not a "problem" per se. It is just how Vim has been working for decades: grep's output is printed in Vim's parent shell and you must press <CR> to come back cleanly to Vim. I never found that mechanism as refined as I wanted it to be, hence the "solution", but it is not unusable at all.

The latter is a real problem. The tricks in my gist should solve it but not directly. Something (or a combination of things) in your setup is behaving weirdly and bypassing both the terminal emulator and the shell effectively hides it, but the problem is still there and, IMO, needs fixing.

I would start by checking if the bad behavior also happens in other terminal emulator/shell/$TERM combinations.

FWIW, the proper $TERM for Kitty is xterm-kitty, not xterm-256color. I would set that correctly before even trying different combos.

2
  • 2
    I would be curious to know how you managed to solve your problem with the information included in this overblown comment.
    – romainl
    Commented Jul 3 at 3:29
  • I only switched to cgetexpr system(...)commands as your gist explained. I wasn't bothered to try to fiddle with my TERM settings at the moment; I believe I had set it this way for some reason, and since I use vim as my terminal multiplexer, basically nothing else writes to my terminal without going through vim, and the scrollback etc inside vim's terminals work perfectly fine for me. I will note that under my main setup, I see that ENTER after :grep! leaves the screen intact, but ENTER after :silent! grep! leaves garbled text on the screen stubbornly, requiring a manual refresh to clear. Commented Jul 3 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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