Goto top of *grep* buffer after each run of grep

I like to read my grep results from top to bottom, but grep.kak always leaves the cursor at the bottom of the buffer. I’m trying to figure out how to move it to the top after each time I’ve run grep. So far I’ve tried just directly executing the following in the prompt:

grep $kak_selection ; execute-keys gg

That will run grep, but my cursor never moves to the top of the buffer. I’m thinking this has to do with grep.kak using a fifo buffer. Maybe there is no actual content in the buffer when the execute-keys gg is run, so the content shows up just milliseconds later.

So instead I went the route of trying to use hooks to execute-keys gg only after the fifo buffer updates:

hook global BufCreate '\*grep\*' %{
	hook buffer BufReadFifo '.*' %{
		execute-keys gg
	}
}

This seems to not work either (I did confirm that the hook executes by inserting a little echo -debug line in there).

Anybody got any ideas as to how I can make this happen?

thanks :wave:

Remove -scroll in grep.kak and open an issue to be configurable.

edit! -fifo ${output} -scroll *grep*

Ah, I didn’t realize -scroll was a thing. Thanks for pointing me that way.

PR created!

1 Like