Multi-grep workflow improvements

#1

map global user g %{<A-i>w,m<esc>:grep <C-r>.<ret><esc>:evaluate-commands %sh{echo rename-buffer *grep*:`uuidgen`}<ret>}

I am loving having multiple grep’s that I can walk forward and back across with C-o C-i – what I am looking to improve is two things.

  1. Rather than a uuid, use the search term (feels fairly straightforward, but don’t have it yet, because it has to be used multiple times
  2. Make grep next and grep prev use the latest one I either (a) ran or (b) traversed… can’t decide which behavior would be best.
Multiple named grep buffers
#2

I don’t understand the multi-grep workflow and implementation.

  • What does ,m?
  • You can remove the <c-r>. part of grep. With no argument, grep uses the contents of the main selection by default.
#3

,m is kakoune-mark in my config.

So as I grep multiple things they end up highlighted.

#4

@robertmeta I’m lost at following what does the workflow (if you can show me an asciicast :stuck_out_tongue:).

#5

Alex–

Fair enough, it is hard to explain, but I really like it. It doesn’t depend on anything except a search tool (so works across anything) and leaves breadcrumbs I can go back through later. It leaves those grep buffers rather than blowing them up when I do the next grep.

https://asciinema.org/a/nTpcrzzab75O7NzRwAe5OwiX4

#6

You can’t use grep-next-match since you rename the buffer, no?

How about a grep-append command?

#7

Yes, grep-next-match was broken by my rename.

hmpphh… but your idea might actually be even better, if I could put a little like grepped for above those results and a spacer… would grep-next barf on it? I was initially just trying to get the thing I searched for in the buffer name, but appending could be an even more useful workflow, assuming the buffer doesn’t get outrageous in size.

#8
map global user g %{<A-i>w"gy,m<esc>: grep <C-r>g<ret>: try %{delete-buffer *grep*:<C-r>g}<ret> : try %{rename-buffer *grep*:<C-r>g}<ret>}

Slightly better.

1 Like
#9

How about:

define-command grep-add -params .. %{
  try %{
    execute-keys -buffer '*grep*' -save-regs '' '%s"Gy'
    grep %arg(@)
    hook -once 'buffer=*grep*' NormalIdle '' %{
      execute-keys -draft 'gg"GP'
    }
  } catch %{
    grep %arg(@)
  }
}

map global user g '<a-i>w: mark; grep-add<ret>'
map global normal <c-n> ': grep-next-match<ret>'
map global normal <c-p> ': grep-previous-match<ret>'
#10

It appears to be replacing for me, but very cool start. Lots of great ideas.

yeah, the syntax for the mark is : mark-pattern set WHATEVER

#11

find is also a good companion to grep buffers.

#12

One thing that I miss from Vim’s quickfix is that it is a stack, and this gets closer to it being a stack. If it split up the existing matches, pasting 0...grep_current_line before the new matches and grep_current_line...$ after, then it would be a stack proper.