Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
antifuchs opened this issue Nov 15, 2023 · 2 comments
Open

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

antifuchs opened this issue Nov 15, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@antifuchs
Copy link

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:

  • from the end of the line, hit "go back by one syntax element" once; hit "delete the previous syntax element" once; then insert --full-paths. Or,
  • from the start of the line, hit "go forward by one syntax element once; hit "delete the next syntax element" once, insert the replacement.

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

References

@antifuchs antifuchs added the enhancement New feature or request label Nov 15, 2023
@sholderbach
Copy link
Member

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
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants