Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Multiple selections #89

Open
rschmitt opened this issue Jun 14, 2015 · 10 comments
Open

Suggestion: Multiple selections #89

rschmitt opened this issue Jun 14, 2015 · 10 comments

Comments

@rschmitt
Copy link
Contributor

I've realized that for my two main coding use cases (git add and opening files in Vim), I almost always need to select more than one thing. For instance, I'll usually change prod code together with test code, and then want to add both to git:

> CM.java (2/78 choices)
src/main/java/com/github/rschmitt/collider/ClojureMap.java
src/test/java/com/github/rschmitt/collider/ClojureMapTest.java

This quickly gets annoying, since I'll end up typing the exact same query twice for no good reason. If I want to git add (or open), say, five files (which is hardly uncommon), this gets tedious enough that I'll switch to git add -i, git add -p, or copy-and-paste using the mouse, because invoking hs repeatedly is just too cumbersome.

I took the time to whip up a prototype of multi-select functionality in Heatseeker, and so far it really seems like it has legs. It looks like this:
screen shot 2015-06-14 at 1 00 28 pm
Thanks to Rust stabilization, you can now install Heatseeker using Homebrew to play with this feature:

brew install https://raw.githubusercontent.com/rschmitt/heatseeker/master/heatseeker.rb

The controls are:

  • Control-T will toggle the currently highlighted choice and move the cursor down.
  • Enter will select everything that has been selected, as well as the currently highlighted choice.
  • Control-G will select everything that has been selected, but not the current choice, unless it has been selected with Control-T.

To support multiselect, the SelectaCommand script can be modified as follows (note that I'm using this with :tabe rather than :e):

function! SelectaCommand(choice_command, selecta_args, vim_command)
  try
    silent let selections = system(a:choice_command . " | hs " . a:selecta_args)
  catch /Vim:Interrupt/
    redraw!
    return
  endtry
  redraw!
  for selection in split(selections)
    exec a:vim_command . " " . selection
  endfor
endfunction

And the zshrc function insert-selecta-path-in-command-line only needs a one-line change:

selected_path=$(find * -type f | hs | paste -sd' ' -) || return
@BarbzYHOOL
Copy link

i also need this so i'm gonna look at hs

@garybernhardt
Copy link
Owner

If you have <c-s> bound to Selecta/HS in the terminal, then with single selection selection you do:

<c-s>file1<ret><c-s>file2<ret>

And with multiple selections you presumably do:

<c-s>file1<c-t><c-w>file2<ret>

or, if the two files are the top two matches, you don't need to do the <c-w> to delete file from the query, but you do need to do <c-n> to move down to the second file:

<c-s>commonprefix<c-t><c-n><ret>

This looks like the same number of keystrokes either way, but multiple selections requires more UI complexity and, if you're hitting <c-n> at all, it requires reading the screen instead of using muscle memory. What am I missing?

@BarbzYHOOL
Copy link

so multiple selection is there?

@garybernhardt
Copy link
Owner

In Selecta? No, it can only select one line at a time. I'm asking whether there's actually a benefit to having it.

@rschmitt
Copy link
Contributor Author

but you do need to do to move down to the second file:

No, <c-t> selects and moves down. The sequence would be:

<c-s>commonprefix<c-t><c-t><ret>

For what it's worth, since I filed this issue, <ret> selects only the choices that have been selected with <c-t>. It only selects the current choice if nothing has been highlighted with <c-t>.

This looks like the same number of keystrokes either way

If you only have to type the common prefix once, how is it the same number of keystrokes? In a sense, this feature allows you to make a trade-off: you trade away typing at the cost of increased scanning. There are also special cases where you get the best of both worlds.

For example, in Java development, it's common to have LengthyCamelCaseName.java and LengthyCamelCaseNameTest.java; to open them up side-by-side in vim, it's a snap to type

vim -O <c-s>LCCN<c-t><c-t><ret>

without having to read/navigate the screen à la nerdtree.

Another special case is where I actually am exploring an unfamiliar project, not trying to open specific classes. If I've checked out the Apache client and I want to understand how it implements ALPN, one thing I can do is type

vim -p <c-s>Alpn<c-t><c-t><c-n>...<ret><ret>

which allows me to quickly scan and choose from a stable set of choices.

Multi-select is not the most critical feature in the world for a fuzzy-finder, but based on my experience using it over the last few years it is definitely worth the additional complexity.

@garybernhardt
Copy link
Owner

That makes sense, thanks. I'm not sure what I was thinking with that confused common prefix example.

@BarbzYHOOL
Copy link

BarbzYHOOL commented Sep 25, 2018

in fzf it's possible with tab and i used it to select several files in git add

@garybernhardt
Copy link
Owner

@rschmitt, what was your reasoning for ? Did you consider tab too?

@rschmitt
Copy link
Contributor Author

@garybernhardt In Heatseeker, <tab> is an alias for <c-n>. In a typical GUI, <tab> cycles through interface elements without selecting them, so it didn't occur to me to use it for multi-select. <ret> and <space> were already taken, so I ended up with a chord. I think I chose <c-t> by way of analogy with Command-T, or something.

@garybernhardt
Copy link
Owner

Ahh, yeah, it does make sense to me that tab would cycle. Space would make conceptual sense. I never type space into Selecta because it's not useful unless your filenames actually have spaces, and even then the ranking algorithm will generally do fine without needing the space. I wonder if we could get away with using it Maybe it's too late to make that big a change, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants