# Multi-grep workflow improvements

**URL:** <https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500>\
**Category:** Help\
**Tags:** grep\
**Created:** [April 30, 2019, 5:55am UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500 "2019-04-30T05:55:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [April 30, 2019, 5:55am UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/1 "2019-04-30T05:55:39Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![alexherbo2](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/alexherbo2/32/1140_2.png) [@alexherbo2](https://discuss.kakoune.com/u/alexherbo2)\
**Post date:** [April 30, 2019, 11:07am UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/2 "2019-04-30T11:07:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [April 30, 2019, 11:41am UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/3 "2019-04-30T11:41:22Z")

</div>

,m is kakoune-mark in my config.

So as I grep multiple things they end up highlighted.

---

<div class="post-metadata">

**Author:** ![alexherbo2](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/alexherbo2/32/1140_2.png) [@alexherbo2](https://discuss.kakoune.com/u/alexherbo2)\
**Post date:** [April 30, 2019, 1:05pm UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/4 "2019-04-30T13:05:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [April 30, 2019, 2:41pm UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/5 "2019-04-30T14:41:15Z")

</div>

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](https://asciinema.org/a/nTpcrzzab75O7NzRwAe5OwiX4)

---

<div class="post-metadata">

**Author:** ![alexherbo2](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/alexherbo2/32/1140_2.png) [@alexherbo2](https://discuss.kakoune.com/u/alexherbo2)\
**Post date:** [April 30, 2019, 2:58pm UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/6 "2019-04-30T14:58:31Z")

</div>

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

How about a `grep-append` command?

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [April 30, 2019, 3:13pm UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/7 "2019-04-30T15:13:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [May 1, 2019, 1:11am UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/8 "2019-05-01T01:11:06Z")

</div>

```auto
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.

---

<div class="post-metadata">

**Author:** ![alexherbo2](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/alexherbo2/32/1140_2.png) [@alexherbo2](https://discuss.kakoune.com/u/alexherbo2)\
**Post date:** [May 1, 2019, 2:01am UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/9 "2019-05-01T02:01:16Z")

</div>

How about:

```auto
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>'

```

---

<div class="post-metadata">

**Author:** ![robertmeta](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/robertmeta/32/833_2.png) [@robertmeta](https://discuss.kakoune.com/u/robertmeta)\
**Post date:** [May 1, 2019, 2:33am UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/10 "2019-05-01T02:33:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexherbo2](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/alexherbo2/32/1140_2.png) [@alexherbo2](https://discuss.kakoune.com/u/alexherbo2)\
**Post date:** [May 1, 2019, 12:32pm UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/11 "2019-05-01T12:32:42Z")

</div>

[find](https://github.com/occivink/kakoune-find) is also a good companion to grep buffers.

---

<div class="post-metadata">

**Author:** ![eraserhd](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/eraserhd/32/15_2.png) [@eraserhd](https://discuss.kakoune.com/u/eraserhd)\
**Post date:** [May 2, 2019, 11:51am UTC](https://discuss.kakoune.com/t/multi-grep-workflow-improvements/500/12 "2019-05-02T11:51:04Z")

</div>

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.
