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

make Control-w and alt-backspace behave more like bash #632

Closed
wants to merge 4 commits into from

Conversation

alsuren
Copy link

@alsuren alsuren commented Sep 9, 2023

see nushell/nushell#10288 for more context

From the commit messages:

    make control-w behave like bash
    
    'man bash' documents this as:
    
           unix-word-rubout (C-w)
                  Kill the word behind point, using white space as a word boundary.
                  The killed text is saved on the kill-ring.
    
    zsh does not have a concept of small/big words, but its 'word' is slightly
    bigger than nushell's small word, because it includes -./_ and a few other
    punctuation marks.
    
    fish's control-w is slightly larger than nushell's small word in that it
    seems to delete up to the next / (and doesn't need an extra control-w to
    delete the '/' 'thing/').

    make alt+backspace work in vscode by default
    
    On MacOS, vscode generates control-alt-h in response to alt+backspace.
    This is handled in bash as cut-smallword-left and in zsh as cut-word-left
    (zsh doesn't seem to have a concept of small/big words). Fish treats this
    as cut small word left (fish bigwords include anything up to /, and its
    small words stop on any punctuation).

As mentioned in my nushell PR, I realise that keybindings are the kind of thing that can cause holy wars, so I'm happy to back out any changes that people dislike.

'man bash' documents this as:

       unix-word-rubout (C-w)
              Kill the word behind point, using white space as a word boundary.
              The killed text is saved on the kill-ring.

zsh does not have a concept of small/big words, but its 'word' is slightly
bigger than nushell's small word, because it includes -./_ and a few other
punctuation marks.

fish's control-w is slightly larger than nushell's small word in that it
seems to delete up to the next / (and doesn't need an extra control-w to
delete the '/' 'thing/').
On MacOS, vscode generates control-alt-h in response to alt+backspace.
This is handled in bash as cut-smallword-left and in zsh as cut-word-left
(zsh doesn't seem to have a concept of small/big words). Fish treats this
as cut small word left (fish bigwords include anything up to /, and its
small words stop on any punctuation).
@amtoine
Copy link
Member

amtoine commented Sep 9, 2023

from https://github.com/nushell/nushell/pull/10288/files#diff-5c0320ebb54cd8ffd7059eb0178377c5139877d21457f6903439e7caf2e5b40eL585, looks like there might be an additional change to add here to be on par between the two PRs? 😮

@amtoine
Copy link
Member

amtoine commented Sep 10, 2023

okey, looks about right compared to nushell/nushell#10288 👍

@WindSoilder
Copy link
Contributor

Currently in nushell, we think a word doesn't contains -, but other shell don't think so.
I tend to modify word_left_index function, make it behaves more like fish way(which moves up to /, and a word contains -)

pub fn word_left_index(&self) -> usize {

@alsuren
Copy link
Author

alsuren commented Sep 16, 2023

Currently in nushell, we think a word doesn't contains -, but other shell don't think so.

Would it be valuable to add a medium-word concept and leave it up to the end user to configure, or should nushell just "get it right" by default with no configuration?

(I think that making this change is out of scope for this pr, but if there is an easy way to avoid people carrying patches locally, it is worth exploring)

@WindSoilder
Copy link
Contributor

I think we can just change the definition of our "word", if we make it configurable, there are too much things we needs to do: should a word contains -, a word contains _.

I'd like to borrow the idea from fish (https://fishshell.com/docs/current/interactive.html#shared-bindings):

Alt+← and Alt+→ move the cursor one word left or right (to the next space or punctuation mark), Alt+Backspace removes one word backwards.

I've played with fish, and found in fish, a word doesn't contain _ either.

Control+W removes the previous path component (everything up to the previous “/”, “:” or “@”) (moving it to the Copy and paste (Kill Ring)).

@alsuren
Copy link
Author

alsuren commented Oct 22, 2023

I've switched back to using bash, and I've lost momentum on this.

I'm going to close this PR. I will leave the branch up in case anyone wants to cherry-pick from it.

@alsuren alsuren closed this Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants