Skip to content

Feature Request: Match less's default keymap betterΒ #150

@academician

Description

@academician

Greetings! I recently integrated minus into Bat, a popular cat clone with syntax highlighting and some other nice features. Bat still uses (non-managed) less by default, but now includes minus as an optional "builtin" pager. You can test it in the latest version v0.26.0 by passing --pager=builtin.

Is your feature request related to a problem? Please describe.
Following our integration (which was received very well by most users I've seen!), some users noticed that the keybindings don't entirely match less's default keybindings. Specifically, the HOME and END keys don't go to the beginning and end of the file - though there are others.

Describe the solution you'd like
There's an argument to be made that it would be beneficial for minus to try to match less's default keymap as closely as is reasonable, since less is easily the most popular pager. Minus already does a pretty good job - it's just missing a few bindings from its default keymap.

At the very least, adding Home and End bindings that just do what G and g do, respectively, would be an easy win, but there are a few other keys I noticed missing that might make sense to add. I'd like to fully diff the default keymap of less and minus to find the areas they differ by, but haven't spent the time yet.

I also found at least one conflict with less's keybindings, namely p, which in minus goes to the previous match but in less it's: "Go to beginning of file (or N percent into file)". For equivalent behavior less follows vi's lead by using n and N for "next match" and "previous match", but the direction of each depends on if the last search used / or ?.

Here's a few of my personal, subjective "low hanging fruit" list of missing keymaps that exist in less:

key description existing minus equivalent
Home Go to the top of input g
End Go to the bottom of the output G but without "n"
[n] N Go to the (nth) previous search match** None
-N Toggle line numbers Ctrl-L

**: Ie, backwards if the last search was /, forwards if the last search was ?

Other nice-to-haves might include h/H for "help" (thought that should probably be its own feature request!) and the "ex"-style bindings like :q, :Q, :f

Describe alternatives you've considered
Because minus is awesome, we could add some of the desired keybindings (like Home and End) ourselves pretty easily. I already did that locally as a test and it was about two lines of code, so...not a big deal. However, my gut feeling is that this would be better upstreamed into minus so that other users will benefit from it.

The possible downside is that by adding new default keybindings, it's possible there are other downstream consumers of minus that don't want the defaults to change. This is almost unavoidable in any library, of course, but does mean this change would merit a minor version bump

Additional context

  • Lesskey is the tool used for customizing less's keybindings, and has some more granular technical information
  • Here's a gist with the output of less --help from less v590

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