hydra.nvim icon indicating copy to clipboard operation
hydra.nvim copied to clipboard

Feature Request: Allow `foreign_keys = 'compose'`

Open atchim opened this issue 3 years ago • 3 comments

A Brief Use Case

Let's suppose that the user wants to have a hydra for the <C-W> mappings, so they write the following configuration.

local hydra = require'hydra'
hydra {
  name = 'Window',
  body = '<C-W>',
  heads = {
    {'h', '<C-W>h'},
    {'j', '<C-W>j'},
    {'k', '<C-W>k'},
    {'l', '<C-W>l'},
  },
}

Now let's suppose the following.

  • The user pressed <C-W>l to move to the window in the right, triggering the l head, which means that the hydra state is on.
  • The user pressed q to close that window and nothing happened, since the q head doesn't exist.
  • The user pressed q again desperately trying to close it.
  • The q macro has started to be recorded.

The Proposal

I think that would be nice to have an option to set foreign_keys to compose, or another meaningful name, in order to evaluate the mappings resulted of the composition of the hydra's body with the non-head key pressed. Still using the previous situation as example, if the proposed option was enabled, the first time that the used pressed q would trigger the <C-W>q mapping.

This would be useful for the following cases.

  • When there's too much mappings derived from a body and the user doesn't want to write all those heads, but they still wants the valid derived mappings to behave similar as it were a head.
  • When a key mapping doesn't make much sense to be a head, since the user doesn't expect to keep pressing another heads afterwards.
    • E.g., when we press <C-W>= to balance the windows, we usually don't intend to perform another window mappings.

atchim avatar Aug 01 '22 07:08 atchim

In other words, you want all other keys to be blue heads. Is this concept applicable somewhere beside window management?

anuvyklack avatar Aug 01 '22 18:08 anuvyklack

@anuvyklack, I think it is applicable, but I guess it would be a kind of occasional use.

atchim avatar Aug 01 '22 21:08 atchim

@atchim: That would be so useful!

I'm struggling to find a sane plugin which will show a pop-up with possible further actions based on input.

Currently I'm torn between folke's which-key.nvim and this plugin. Most of my config is still with which-key but it has lots of issues (no sticky keys, order of keys is lost), so I'm leaning towards hydra which looks very promising.

I want to keep the info in pop-up minimal, showing only what I usually use, without disabling the default behavior.

For now I've only configured hydra for z and g command prefixes, but the problem is that I don't want to define every vanilla combination possible, like g<Down> or g<End>, but I still want them to be accessible when I'm in hydra's g menu.

@anuvyklack: I think all other possible mappings becoming being blue heads would be a good start!

EtiamNullam avatar Jan 12 '23 01:01 EtiamNullam