linenoise icon indicating copy to clipboard operation
linenoise copied to clipboard

vi bindings

Open saysjonathan opened this issue 10 years ago • 12 comments

This change introduces vi bindings while maintaining the original API. A shim function was created that enables vi mode then passes off to the normal API, linenoise().

A few additional functions were created to support common key actions, including:

  • linenoiseEditMovePrevWord
  • linenoiseEditMoveNextWord
  • linenoiseEditDeleteNextWord

The bindings are not meant to be comprehensive but to provide basic functionality by implementing the most common actions.

example.c was also updated to introduce a new flag that enables vi bindings.

saysjonathan avatar May 03 '15 22:05 saysjonathan

+1 the patch looks fine

dumblob avatar Oct 03 '15 11:10 dumblob

Any blocks to merging this? It'd be reeeaaaaaalllly nice to have.

eggsyntax avatar Jan 22 '16 23:01 eggsyntax

@saysjonathan do you plan to resolve the merge conflicts any time soon?

dumblob avatar Jun 25 '16 10:06 dumblob

FWIW, I think the algorithm in #64 is closer to vim's behavior (and readline's, for that matter). Few implementations I've seen consider only spaces to be word boundaries.

lethosor avatar Jun 28 '16 02:06 lethosor

@lethosor the algorithm seems a bit better, but it won't be accepted as it completely changes the library - namely it seems to switch from C to C++, which is a great pity. @wingeng, do you have any plans to make it compatible with the ideas linenoise was built around?

dumblob avatar Apr 14 '17 11:04 dumblob

Sorry, that branch changed a lot since I mentioned it - I was referring to just the first 3 commits in that PR.

lethosor avatar Apr 14 '17 12:04 lethosor

@dumblob Wow, been a long time since I saw this code. Sorry about the massive changes to the code-base, the style was driving me nuts. I don't have much time now-a-days to work on this... but I may in a couple of weeks as some current work projects may allow me to revisit this.

BTW, did you just want the fixes to the word boundaries navigation? That was done prior to the C++ switch over.

wingeng avatar Apr 14 '17 13:04 wingeng

The code looks well written and does not change radically the linenoise code base in order to add such a support, however the question is if it's a fit for a small library to add such a mode. The code complexity will get a bit bigger but the concept of ANSI-C single file remains. Not sure... Btw I'm a vim user myself and I use the vim mode in zsh sometimes, but vim modes in the end tend to be very limited, naturally, so it is never a great experience. But still I use it in order to immediately move across the line. Any hint?

antirez avatar Apr 14 '17 14:04 antirez

...the vim mode in zsh sometimes, but vim modes in the end tend to be very limited, naturally, so it is never a great experience. But still I use it in order to immediately move across the line. Any hint?

Well, it is not the best experience (compared to (n)vim, whose feature set can't be even reached because of the shell semantics), but on my side it saves me a huge amount of time (and saves me from swearing "how slow and error-prone it is to work with pure POSIX shell" and thus makes me way more comfortable) when it comes to a command line work. I actually use in shell (mostly Bash) nearly all the commands from the original vi, so I can say the set -o vi mode is powerful and very handy.

Do you @antirez also use the full power of set -o vi in zsh or rather really just "immediate moving across the line"? Could you also please elaborate what exactly you mean with the question "Any hint?"?

dumblob avatar Apr 15 '17 16:04 dumblob

Having a vi mode is a serious accessibility issue for people for whom repeated keyboard chording causes physical pain (e.g. http://ergoemacs.org/emacs/emacs_kb_shortcuts_pain.html). I use vi emulation in Emacs for this reason. So I hope you will please merge the vi bindings.

michael-776 avatar Jul 22 '17 16:07 michael-776

@michael-776 You know you can fork the linenoise repo and mod it to your hearts content? Right? I use a customized linenoise with changes specific to my needs/tastes: https://github.com/Sonophoto/linenoise/commits/master/linenoise.c I haven't used the "official" linenoise in years...

Sonophoto avatar Jul 25 '17 20:07 Sonophoto

@Sonophoto RE: "you know you can fork the linenoise repo and mod it to your hearts content?"

I do know, yes, thanks for the suggestion. But I'm not a C programmer, and lots of other people aren't either. I was just throwing my two cents in on the usefulness of having a vi mode. Well.. and making a plea for help, I admit :)

michael-776 avatar Jul 25 '17 22:07 michael-776