Enhanced abbreviations #8854
Replies: 3 comments 2 replies
-
Looks really solid. I have some thoughts but no objections. I understand (regex) matching is done on the unexpanded tokens (so a literal I wonder if/how we want to cover abbreviations for subcommands (#6283). Vim expands abbreviations at word boundaries. We expand on space. Couple more examples:
Most importantly they have low risk of false positives, because the inputs are invalid syntax. Some of these would benefit from abbreviation-expansion at word boundaries. If we could do it without a breaking change, I think |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for working on this.
FWIW, I would like to discuss 2 other features.
I would be interested in
Regarding the 2nd bullet point, consider this:
So far, so good. Now, suppose you made a typo, and you want to replace
Finally, you press Enter. I know it's working as intended, but I still find this confusing. I would like the ability to limit the expansion to after a space only. It might also be useful to let us specify the cursor position after the expansion. For example:
With
Suppose you want to clone the fish project. You type
Instead, you would like this command-line:
So that you can paste the url of the fish repo without having to move the cursor first. This could be achieved with a
Even better would be to let us write a special token inside the expansion to express where we want the cursor to be:
|
Beta Was this translation helpful? Give feedback.
-
One other thing that would be nice from my perspective (as I’m trying to retrain more than a decade of Git use to use new porcelain). I’d love to be able to perform more complex substitutions that aren’t just single tokens. That is, I find myself typing |
Beta Was this translation helpful? Give feedback.
-
Here's some ideas around enhanced abbreviations. I intend to implement these if others agree. Let me know what you think!
Recall that abbreviations have a name and a replacement. If the user types an abbreviation in command position, it gets replaced with a value.
abbr gco 'git checkout'
is an example.I would like to extend this feature to give users a high degree of customization, similar to key bindings. Here's my proposed signature:
Here's what these new options do:
--position command | anywhere
Today abbreviations only expand in "command position." If you pass
--position anywhere
they expand anywhere. The default remainscommand
. See #5003.--expands-on entry | execute
Today an abbreviation expands after the user types a space, or enter. If you pass
--expands-on execute
it expands only on enter. History receives the command before expansion, allowing abbreviations to work better with history and autosuggestions.The default remains
entry
.--regex PATTERN
Today, an abbreviation replaces its name with its value. With
--regex
the user can supply an arbitrary regex to describe the token to replace. The abbreviation still has a name so it can be identified, but it doesn't contribute to matching.Initially only single tokens can be matched. We'll use PCRE2 of course.
If multiple abbreviations have a matching regexp, the last one takes precedence. This means the order of abbreviations may matter.
--function
Lastly, the
--function
flag indicates that REPLACEMENT should be interpreted as a fish function name. To generate the replacement, fish invokes the function, passing it the token which matched. If the function succeeds (returns 0) its output is used to replace the token. If it fails, no replacement occurs.Examples
Some examples of stuff you can do. Not saying any of these are good ideas, except the first I think we should ship as an example.
We can easily support
!!
(see #288)You can go a little nuts and implement more of history expansion:
You can also use it as a sort of superpowered key binding. This enables
<E...>
syntax to insert emojis by name:Other notes
Abbreviations will no longer be managed by universal variables; instead they will be managed internally like key bindings. This is because abbreviations now have a lot more metadata which is unwieldy to attach to just variables; it's also consistent with our desire to move away from uvars.
The existing behavior where
abbr
sets a universal variable will no longer work. Instead users will have to add abbreviations toconfig.fish
or elsewhere. The-U
and-g
flags will be ignored. We will continue to import existing universal-variable backed abbreviations, so we don't break existing configs.Abbreviations remain an interactive feature only. They do not work in scripts.
Thank you for any thoughts!
Beta Was this translation helpful? Give feedback.
All reactions