Feature request: Key sequences as binds #67

Closed
evaryont opened this Issue Jun 14, 2012 · 13 comments

Comments

Projects
None yet
4 participants

It would be awesome if you could add key sequence support. I imagine that you would add a new key bind type, perhaps something like this:

(in ~/.tigrc)

bind generic g wait
bind generic gd view-diff
bind generic gt view-tree

My reasoning is to make tig's keybinds closer to my vim configuration's.

Contributor

vivien commented Jun 16, 2012

Hi, if you want something more close to Vim, did you try the Fugitive plugin?

Yeah, I've tried messing with it. I can't seem to get it started automatically. I am also more interested in using tig's pager functionality, called via git aliases.

I just like vim's key bindings, and like a consistent layout between all the programs I use. :-)

Contributor

vivien commented Jun 19, 2012

I feel like this would be a lot of development effort for such a small feature.
Why not just get your gd, and gt key sequences to work with this?

bind generic g none
bind generic d view-diff
bind generic t view-tree

jonas added a commit that referenced this issue Apr 18, 2014

prompt: expose API to incrementally receive key events
This API will allow to read key combos (issue #272 and issue #67) and
add support for incremental search (issue #5).
Contributor

cirosantilli commented Apr 18, 2014

What I would love to write in my tigrc to achieve this effect is something along:

namespace g
  bind generic d view-diff
  bind generic gt view-tree
end

Not sure how feasible this is, but it is DRY and looks like Rails / Django route files =)

Owner

jonas commented Apr 18, 2014

Something like the following is already parsable (with the right modification in src/options.c)

bind generic gd view-diff
bind generic gt view-tree

If we want to extend the "format" to also support non-alphabetic keys (e.g. PageUp) I suggest we take Vim's approach and add support for:

bind generic < parent               # '<' without '>' means the '<' key
bind generic <Esc>v scroll-page-up
bind generic ^x<PageUp> view-tree   # Ctrl-x + PageUp will open the tree view
Contributor

vivien commented Apr 18, 2014

@cirosantilli I'm not a fan of the namespace block. I prefer a flat config file with two lines and the explicit key sequences. (that's just my opinion)

Contributor

cirosantilli commented Apr 18, 2014

@vivien no problem, you are much more involved in the project and I definitely want to hear you out.

What is the downside of using namespaces that concern you?

The advantage of course is that if you want to change the prefix for several bindings you just have to change one line.

I'm also a fan of a flat configuration file as well. namespace might look similar to Rails routes, but it's very different than most text editor's configuration syntax.

Owner

jonas commented Apr 28, 2014

As of commit 837cc38 , key mappings now expect a Vim-inspired syntax for keys. Errors are reported for old syntax (^f, ^[o, < and Down) to make it easier to upgrade existing key mappings. Finally, the goal will be to introduce full support for key combos after 2.0.

bind main <Down> next       # Symbolic key mapping
bind main <LessThan> back   # Maps to '<'
bind main <Esc>o options    # Esc key combo
bind main <Ctrl-f> search   # Control key mapping; short format <C-f>

jonas added a commit that referenced this issue May 7, 2014

Experimental support for key combos
This adds experimental support for key combos. Key combos are read using
a new input handler. For each key it scans all key bindings for matches.
If an exact match is found that binding is triggered else it will wait
for the next key.

Fixes #67
Owner

jonas commented May 7, 2014

The gh-67 branch has an experimental patch for key combos. It doesn't change the internal structure for how keybindings are stored but simply scans every keybinding each time.

There are still some bike shedding and improvements left to do before this can be merged:

  • What should be the timeout for triggering "shorter" key combos, e.g. o vs og? (not implemented yet)
  • Should the current combo keys be shown in the status view? (they currently are)
  • How should escaping work? Currently, Esc cancels the key combo unless it is the first key in the combo. This means that you cannot have combos like o<Esc>.

In terms of merging this patch, I suggest we start by making support for key combos disabled by default in version 2.1 and then enabling it by default in version 2.2. This way people upgrading from 1.x will still receive upgrade error messages in version 2.1.

jonas added a commit that referenced this issue Feb 10, 2015

Experimental support for key combos
This adds experimental support for key combos. Key combos are read using
a new input handler. For each key it scans all key bindings for matches.
If an exact match is found that binding is triggered else it will wait
for the next key.

Fixes #67

@jonas jonas closed this in c1def71 Mar 11, 2015

Contributor

vivien commented Mar 11, 2015

There are still some bike shedding and improvements left to do before this can be merged:

  • What should be the timeout for triggering "shorter" key combos, e.g. o vs og? (not implemented yet)

No timeout. If og exists, o cannot be bound. This is how Vim actually behaves and it feels simple and natural: pressing g prints the key in the status line and waits indefinitely for a next key. Pressing Esc cancels the key sequence, but pressing for instance j executes the gj sequence (unless a sequence starting with gj exists, for sure. A complex example for Vim is the gUiw sequence).

  • Should the current combo keys be shown in the status view? (they currently are)

IMO, Yes.

  • How should escaping work? Currently, Esc cancels the key combo unless it is the first key in the combo. This means that you cannot have combos like o.

The current behavior is fine.

If og exists, o cannot be bound.

Slight correction, you can actually bind shorter key sequences. Vim has a timeout (I think 2 seconds by default) that it waits. If you have o & og bound, pressing o and waiting 2 seconds will then execute the mapping for o. Annoying and not recommended, but it does exist.

The behavior described is fine with me. Thanks for all of the work!

Contributor

vivien commented Mar 11, 2015

Thanks for the clarification @evaryont, I didn't know that behavior in Vim!

Indeed, key timeout is hell, it reminds me of using this crappy remote, where you end up on channel "333" when you initially wanted to jump to channel 3...

vivien added a commit to vivien/tig that referenced this issue Mar 11, 2015

vivien added a commit to vivien/tig that referenced this issue Mar 28, 2015

contrib: complete Vim-like bindings
This commit is a first draft to add more Vim-ish bindings to vim.tigrc,
which are also good examples for multi-key bindings.

Refs #67 #273 #351

@jonas jonas modified the milestones: tig-2.2, tig-2.1.1 Apr 9, 2015

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