helix icon indicating copy to clipboard operation
helix copied to clipboard

interactive global search

Open dofinn opened this issue 4 years ago • 26 comments

The reason I use vim is for ripgrep and fzf. This makes for extremly fast navigation.

Request:

  • Ability to index files in active directory and search via FZF 20210609_224940_grim

  • Ability to grep through fies in active directory and pipe results in fzf

  • ripgrep file_config | fzf <- this opens up in same preview window that FZF provides. 20210609_225128_grim 20210609_225136_grim

There are many blogs etc writing about this method in vim. EG: https://sidneyliebrand.medium.com/how-fzf-and-ripgrep-improved-my-workflow-61c7ca212861

dofinn avatar Jun 09 '21 12:06 dofinn

Should this be a core feature of Helix or be implemented as a plugin?

kirawi avatar Jun 09 '21 16:06 kirawi

I personally think this should be core feature. We already have like skim like thing, implementing ripgrep is just near.

pickfire avatar Jun 09 '21 16:06 pickfire

is a dependecy on ripgrep something you want to make mandatory? I would imagine having these functions pluggable grep=plugin(ripgrep) find=plugin(fzf)

dofinn avatar Jun 10 '21 00:06 dofinn

I don't think we will pull in ripgrep. We may be implementing our own which is slightly slower compared to ripgrep but work well for our usecase.

pickfire avatar Jun 10 '21 03:06 pickfire

We could also just import the grep_searcher crate that ripgrep uses internally. It's published to crates.io

https://docs.rs/grep-searcher/0.1.7/grep_searcher/

And walkdir for recursive file system traversal https://docs.rs/walkdir/2.3.2/walkdir/

vv9k avatar Jun 10 '21 04:06 vv9k

so excuse me for being an idiot. The file picker is already aweesome! cancel the FZF request

dofinn avatar Jun 10 '21 11:06 dofinn

I do think a preview window + some way to actually search through files would be useful though :)

I think there should be a general way to pipe data into the built-in picker.

archseer avatar Jun 11 '21 02:06 archseer

I agree, after using it last night i did miss the preview window + the actual fuzzy finding where i could use multiple terms seperated by whitespace rather then the exact path/to/target/file

dofinn avatar Jun 11 '21 03:06 dofinn

The finding is fuzzy (we use skim's algorithm, we just don't highlight the matched characters yet.

archseer avatar Jun 11 '21 03:06 archseer

Does Helix use skim as a library?

nrdxp avatar Jun 15 '21 16:06 nrdxp

Does Helix use skim as a library?

We're using the fuzzy-matcher crate which is used internally by skim.

sudormrfbin avatar Jun 15 '21 16:06 sudormrfbin

Another vote for searching via the grep_searcher crate in the preview UI used for the picker, per https://github.com/helix-editor/helix/issues/196#issuecomment-858283651

heliostatic avatar Aug 19 '21 01:08 heliostatic

Hi! I too think that being able to perform a search in current workspace would be immensely helpful. So I started messing around and implemented something myself . It's not pretty I know, but it's something for us to talk about as least. My implementation bind space + / to display a prompt (like the search prompt), and on Enter, start the search, gathers the result and pop up a FilePicker. A few necessary changes are made, such as regex_prompt now accepts an extra callback that would be invoked once Enter is pressed. There may be some best practices I missed or some corner cases that I don't know about, but hopefully this can be improved by the community. So before I rush to create a PR, I just want to know if you guys have any thought on what this should look like and how it should be properly implemented. Thank you!

pppKin avatar Aug 25 '21 08:08 pppKin

That's pretty cool! I think instead of grep you will want to import grep_matcher and grep_regex so we avoid some of the extra deps (we don't need grep_printer for example). grep is just a facade that re-exports all these crates: https://github.com/BurntSushi/ripgrep/blob/master/crates/grep/src/lib.rs

I'm also wondering if we might want to do this without the prompt and just do this interactively in the picker as the user types. It's a bit wasteful though so maybe there could be a key to refresh (ctrl-r or something like it)

The binary detection part is really cool and we likely want to use that in the file preview as well to avoid displaying binary files (on space + f).

archseer avatar Aug 25 '21 08:08 archseer

import grep_matcher and grep_regex so we avoid some of the extra deps (we don't need grep_printer for example)

You're right, I will be cleaning it up shortly :)

Edited: Updated. But I seem to have messed up my forked branch to include a commit that was not mine(due to some incorrect git rebase I think), after resolving that I'll be creating a PR so that it's easier for everyone to review:)

pppKin avatar Aug 25 '21 08:08 pppKin

just do this interactively in the picker as the user types

@archseer Interactive picker might be a more intuitive option, but I wonder what would be a proper way to fuzzily select a file in search results in said picker? Perhaps add another input field and another key binding to switch between them?

pppKin avatar Aug 25 '21 10:08 pppKin

That would be an option, but from what I've seen in other plugins (telescope.nvim) there's simply no fuzzy file select, you just scroll the list (we could probably add ctrl-d/u page up/down so the list is easier to scroll faster). When I'm searching for something I usually don't know the filename so I'll traverse the list to find the correct entry.

I do see a case for being able to limit the set of files we search for beforehand though, for example if I'm searching for results inside _test.go files. In that case I think we could space + f, _test.go to fuzzy find files, then space + \ should search through that subset of files.

archseer avatar Aug 26 '21 02:08 archseer

@archseer I think this is implemented, any reason to keep this open?

EpocSquadron avatar Oct 31 '21 17:10 EpocSquadron

Interactive prompt is not available yet so it will be kept open.

pickfire avatar Nov 14 '21 02:11 pickfire

any update on this? I can take a crack at it if not.

weakphish avatar Sep 12 '22 21:09 weakphish

Have you looked at the linked PRs? Requires https://github.com/helix-editor/helix/pull/3172 and https://github.com/helix-editor/helix/pull/3110

archseer avatar Sep 13 '22 00:09 archseer

@archseer I see #3110 linked above, but not #3172 . Is there an open PR for this feature which explicitly depends on #3172 and #3110 or are you saying that no work fro this feature can/will be done until those two PRs are merged?

johnrichardrinehart avatar Oct 10 '22 14:10 johnrichardrinehart

There's no open PR for this issue, but the code in #3110 and #3172 introduce a kind of picker that allows re-populating it with different results whenever the search query changes instead of simply filtering the list, which is essentially what we need for an interactive search (re-run the global search whenever the query changes and inject into the list).

sudormrfbin avatar Oct 10 '22 16:10 sudormrfbin

I understand. #3172 has been merged 🎉. I understand there's some desire to to block #3110 on a debouncing feature. But, I'm worried that this may further delay the implementation of this feature - especially since no one has yet complained about input lag that would be ameliorated by the denouncing (not that they'd really had the chance, but addressing performance problems before they're identified as issues maybe shouldn't block new features).

johnrichardrinehart avatar Oct 11 '22 08:10 johnrichardrinehart

I was initially going to put the debouncing as a TODO, but I could already experience input lag on a release build with rust-analyzer as a test case LSP if I type with the speed of knowing exactly what I'm looking for. Granted it's not a huge blocker, but I'd like to get them in together.

sudormrfbin avatar Oct 11 '22 16:10 sudormrfbin

Okay, I understand. Thanks for your contributions to this project and I look forward to testing/playing with your work!

johnrichardrinehart avatar Oct 20 '22 08:10 johnrichardrinehart

I came up with nushell script command interactive global search (external to helix) using rg and fzf, so also works on MS Windows It shows only with single line of preview, but still quite usable. For nushell users, put this in of your config.nu:

def rghx [] {
  let li = ((rg -e '.' --no-heading -n --color always | fzf --ansi) | lines |  split row ':')
  hx ([$li.0, ':', $li.1] | str join)  
}

run it in the repo root folder, and start typing to search, enter to open in helix

can be easily translated to different shell script

amstaniec avatar Feb 01 '23 10:02 amstaniec

This is something I use in bash

#!/bin/bash

# Search using rg and fzf with preview
out=$(rg . --line-number --column --no-heading --glob '!.git' | \
      fzf +i --exact --delimiter : --preview 'batcat --style=full --color=always --highlight-line {2} {1}' --preview-window 'up,~4,+{2}+4/2')

# Remove cruft leaving something like: 'file:line:column'
ref=$(echo $out | sed -E 's/([a-zA-Z0-9/-_]*):([0-9]*):([0-9]*):.*/\1:\2:\3/')
hx $ref

Would be super useful to open the found file in a running instance of helix... Is there a hack to do this?

davxy avatar Feb 01 '23 18:02 davxy

I'm not sure about the running instance, but you can open it in new one by editing FZF_DEFAULT_OPTS variable and adding something like this:

export FZF_DEFAULT_OPTS='... ,ctrl-o:execute(hx $(echo {} | cut -d ":" -f1))

I have this in my .zprofile since I'm using zsh, check where you shell sets FZF_DEFAULT_OPTS.

predmijat avatar Feb 01 '23 20:02 predmijat

@davxy, and anyone else interested: I hacked something together for this, you can read about it on my post on r/HelixEditor.

obxhdx avatar Jun 01 '23 19:06 obxhdx