ronisbr / TerminalPager.jl

Pure Julia implementation of the command less
MIT License
116 stars 8 forks source link

[Feature] Vi-Like Key Navigation? #7

Closed TheCedarPrince closed 3 years ago

TheCedarPrince commented 3 years ago

This is AMAZING! I think I will start using this tool in my daily workflow. Great work @ronisbr!

Just a suggestion, but would it be possible to add in vi-like keybinds for navigating? Alongside the arrow keys working, it would be great to have h, j, k, l support and things like Ctrl + d or Ctrl + u for chunked navigation. Is this a good idea or not so much? Happy to look into contributing on that aspect. Thanks!

ronisbr commented 3 years ago

This is AMAZING! I think I will start using this tool in my daily workflow. Great work @ronisbr!

Thanks! I hope it will be useful :)

Just a suggestion, but would it be possible to add in vi-like keybinds for navigating? Alongside the arrow keys working, it would be great to have h, j, k, l support and things like Ctrl + d or Ctrl + u for chunked navigation. Is this a good idea or not so much? Happy to look into contributing on that aspect. Thanks!

Yes, we can do this! In fact, for those single keybindings you can do this right now (I am not sure if we should make this default or not, perhaps we can add a vim-mode to change the default keybindings?)

julia> using TerminalPager

julia> TerminalPager.set_keybinding('h', :left)

julia> TerminalPager.set_keybinding('j', :down)

julia> TerminalPager.set_keybinding('k', :up)

julia> TerminalPager.set_keybinding('l', :right)

For CTRL+d or CTRL+u I can add new actions to scroll half the screen as in default vim behavior. However, I am using CTRD+D (end of transmission) to quit the pager, but I can be configurable.

Maybe having an option to turn vim-mode is the best one. What do you think?

P.S.: command with more that one character, like gg, will take a little more to implement.

TheCedarPrince commented 3 years ago

Hey @ronisbr - I like the idea of making vim keybinds an optional mode such that you could have something in your startup.jl like ENV["PAGER_MODE"] = vi or ENV["PAGER_MODE"] = default. For me, I think it would be a bit of a pain to manually have to call those set_keybinding commands from my startup.jl. What do you think?

ronisbr commented 3 years ago

Nice! This idea to add an environment variable is just amazing! I will do that :) Thanks for the suggestion!

ronisbr commented 3 years ago

Question: in vi mode, do we map arrow keys together with hjkl?

TheCedarPrince commented 3 years ago

Yea! Let me know if you need any assistance. Happy to test. :)

I think mapping the arrow keys with hjkl is reasonable as that is also valid in vim.

ronisbr commented 3 years ago

Actually, only CTRL+D and CTRL+U needed the special treatment of PAGER_MODE=vi :) I also did not implement multiple keystrokes commands (like gg) since it will add some intricate logic. However, g goes to the beginning, so gg will go to the beginning twice :D

I implemented h j k l 0 $ CTRL+D CTRL+U. Did I miss something?

TheCedarPrince commented 3 years ago

@ronisbr - I think the only other thing I can think of is capital G which goes to the bottom of the pager. Otherwise, great work! Looking forward to trying this out!

ronisbr commented 3 years ago

Yes! I forgot to list G but it should be working. Let me know please if you have problems.

TheCedarPrince commented 3 years ago

For sure! Is it already released or is it coming out in the next version?

ronisbr commented 3 years ago

it is in main. I will release as soon as I finish the initial documentation.

TheCedarPrince commented 3 years ago

Ah shoot @ronisbr - I forgot that in some systems, things like Ctrl+D or Ctrl+U would cancel the current on-going command. For right now, Ctrl+D does not work on mac in the pager mode as it closes the pager view. :/

ronisbr commented 3 years ago

Hum, that's strange. I am using macOS (iTerm) and CTRL+D works perfectly. If I start Julia with PAGER_MODE=vi julia and call the pager, CTRL+D and CTRL+U go down and up. If not, then CTRL+D exits the pager. Can you tell me more details about your setup?