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

Change vi-mode tilde to toggle character case #6908

Merged

Conversation

joelakuhn
Copy link
Contributor

This updates the behavior of tilde to match the behavior found in vim.
In vim, tilde toggles the case of the character under the cursor and
advances one character. In visual mode, the case of each selected
character is toggled, the cursor position moves to the beginning of
the selection, and the mode is changed to normal. In fish, tilde
capitalizes the current letter and advances one word. There is no
current tilde command for visual mode in fish.

Description

This patch adds the readline commands togglecase-letter and
togglecase-selection to match the behavior of vim more closely. The
only difference is that in visual mode, the cursor is not modified.
Modifying the cursor in visual mode would require either moving it in
togglecase-selection, which seems outside its scope or adding
something like a move-to-selection-start readline command.

This updates the behavior of tilde to match the behavior found in vim.
In vim, tilde toggles the case of the character under the cursor and
advances one character. In visual mode, the case of each selected
character is toggled, the cursor position moves to the beginning of
the selection, and the mode is changed to normal. In fish, tilde
capitalizes the current letter and advances one word. There is no
current tilde command for visual mode in fish.

This patch adds the readline commands `togglecase-letter` and
`togglecase-selection` to match the behavior of vim more closely. The
only difference is that in visual mode, the cursor is not modified.
Modifying the cursor in visual mode would require either moving it in
`togglecase-selection`, which seems outside its scope or adding
something like a `move-to-selection-start` readline command.
@krobelus krobelus added this to the fish 3.2.0 milestone Apr 17, 2020
@krobelus krobelus merged commit a3dfa21 into fish-shell:master Apr 18, 2020
@krobelus
Copy link
Member

Nice contribution, thank you!

@joelakuhn
Copy link
Contributor Author

Awesome! That's been slightly bugging me for like 8 years and I finally took the time to fix it. There are other vi-mode enhancements like adding matching brace movement and inner and outer brace text objects I'd like to work on if that would be welcome.

@krobelus
Copy link
Member

Awesome! That's been slightly bugging me for like 8 years and I finally took the time to fix it. There are other vi-mode enhancements like adding matching brace movement and inner and outer brace text objects I'd like to work on if that would be welcome.

Sure, bindings for % and cib would make a lot of sense. It's never too late to scratch those itches ;)
There could also be a "job" text object, delimited by any of ; \n & && || #, or "process" which is delimited by |, too.

Of course, heavy duty editing can always be done with \ev or \ee, but using fish as line editor interacts nicely with autosuggestions and completions.

We might also want to change the default binding of u to the new undo readline command.
I haven't done this because there is already a bind --preset u history-search-backward and I wasn't using Vi mode myself, so I don't know how useful the existing binding is (k does essentially the same thing, right?). Anyway, fish_hybrid_key_bindings seems really nice.

I find the kakoune editing model more intuitive, it's like vi but movements like w and W start or extend the visual selection in addition to moving the cursor. It should be possible to write such bindings already but I doubt anyone has tried yet.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants