nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
547 stars 152 forks source link

Navigating by-argument in addition to by-word #669

Open antifuchs opened 12 months ago

antifuchs commented 12 months ago

Currently, reedline ships key bindings to go to the next/prev word (in emacs mode, that's M-f and M-b). Those are great, but it would be great to complement these with a set of navigation keys that go to the next/prev full "syntax element".

An example to illustrate what I mean: say you're trying to work with a very long command line, and you need to replace a very long element in that command line:

original> ls --short-names "this-is-a-very-long file name"

Assume you'd like to remove that --short-names and replace it with --full-paths. To get there, you can jump to the beginning of the line, then delete the next word twice, or from the end of the line, hit "go back a word" a bunch of times, until you're between the beginning of the string and the end of --short-names, then hit the backwards-delete-word command 6 times (2 words and two hyphens - props for not doing weird things when encountering those, by the way!) .

As a much shorter & more precise way to edit that line, it would be great if there was a way to delete/jump over the entirety of that quoted string (or the --short-names argument), instead of going character-by-character or word-by-word (which stops so many times).

With this feature, editing the command-line would be the following:

This feels much easier and requires much less thought & key-hitting!

References

sholderbach commented 12 months ago

Agreed, that having that syntax aware behavior could make things more delightful (e.g. around the Hinter autosuggestions as well).

As the sane tokenization is syntax dependent, the question would be how we share that responsibility with the shell/application around reedline. Nushell would have a slightly different tokenization compared to a POSIX shell or for example a lisp.

Some general text objects we could provide like the balanced expressions/vim text objects. But there could be things that are language specific. (Flags would be pretty common accross shells but not found in a lot of other languages)

antifuchs commented 12 months ago

I agree that this likely won't ever be fully precise like a language grammar could be: I think having something that can precisely jump over lexer tokens, that would be great already!