Skip to content

Suggestion: Multiple selections #89

Description

@rschmitt

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions